From 242e190ccea30915c617015c4ec2e7aeabbebf01 Mon Sep 17 00:00:00 2001 From: LeoFranklin015 Date: Fri, 19 Apr 2024 01:34:10 +0530 Subject: [PATCH 1/3] Create-Community script --- community/scripts/run.ts | 83 ++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 84 insertions(+) create mode 100644 community/scripts/run.ts diff --git a/community/scripts/run.ts b/community/scripts/run.ts new file mode 100644 index 00000000..c323d844 --- /dev/null +++ b/community/scripts/run.ts @@ -0,0 +1,83 @@ +import { ethers } from "ethers"; +import { GAP, nullRef } from "../../core"; +import { Community, GapIndexerClient, IpfsStorage } from "../../core/class"; + +interface Metadata { + description?: string; + imageURL?: string; + slug?: string; +} + +const [, , communityName, chainId, metadataJson] = process.argv; + +const metadata: Metadata = JSON.parse(metadataJson); + +const walletAddress = "0x5A4830885f12438E00D8f4d98e9Fe083e707698C"; +const GAP_IPFS = "https://gapapi.karmahq.xyz/ipfs"; +const GAP_API = "https://gapapi.karmahq.xyz"; +const PRIVATE_KEY = ""; + +async function bootstrap() { + if (!communityName) { + throw new Error("Please provide a community name"); + } + if (!chainId) { + throw new Error("Please provide a chainID"); + } + if (!metadataJson) { + throw new Error("Please provide a metadataJson"); + } + + const networks = { + 42161: { + name: "arbitrum", + key: "okcKBSKXvLuSCbas6QWGvKuh-IcHHSOr", + }, + 10: { + name: "optimism", + key: "fx2SlVDrPbXwPMQT4v0lRT1PABA16Myl", + }, + 11155420: { + name: "optimism-sepolia", + key: "9FEqTNKmgO7X7ll92ALJrEih7Jjhldf-", + }, + // other networks + }; + + const web3 = new ethers.AlchemyProvider( + networks[chainId].name, + networks[chainId].key + ); + const wallet = new ethers.Wallet(PRIVATE_KEY, web3 as any); + + const gap = new GAP({ + network: networks[chainId].name, + apiClient: new GapIndexerClient(GAP_API), + }); + + try { + const newCommunity = new Community({ + data: { + community: true, + }, + schema: gap.findSchema("Community"), + refUID: nullRef, + recipient: walletAddress, + uid: nullRef, + }); + if (await gap.fetch.slugExists(metadata.slug as string)) { + metadata.slug = await gap.generateSlug(metadata.slug as string); + } + // console.log("Attesting community with metadata", newCommunity.schema.uid); + await newCommunity.attest(wallet as any, { + name: communityName, + description: metadata.description as string, + imageURL: metadata.imageURL as string, + slug: metadata.slug as string, + }); + } catch (error) { + console.log(error); + } +} + +bootstrap(); diff --git a/package.json b/package.json index 1085d00f..c747d357 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "scripts": { "deploy": "npx ts-node ./core/scripts/deploy.ts", "csv-upload": "npx ts-node ./csv-upload/scripts/run.ts", + "create-community": "npx ts-node ./community/scripts/run.ts", "publish-npm": "npm version patch && tsc && cd .dist && npm publish --scope=@show-karma/karma-gap-sdk --access public" }, "dependencies": { From 3ca221b42d0297f3c437d29d3bf1ee3eb785bb09 Mon Sep 17 00:00:00 2001 From: LeoFranklin015 Date: Mon, 22 Apr 2024 15:40:23 +0530 Subject: [PATCH 2/3] changed keys to keys.josn --- community/scripts/run.ts | 17 ++++++++++++++--- config/rpcKeys.example.json | 4 ++++ 2 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 config/rpcKeys.example.json diff --git a/community/scripts/run.ts b/community/scripts/run.ts index c323d844..aabd3d85 100644 --- a/community/scripts/run.ts +++ b/community/scripts/run.ts @@ -28,22 +28,33 @@ async function bootstrap() { throw new Error("Please provide a metadataJson"); } + const { arbitrum: arbitrum_key } = require( + __dirname + "/../../config/rpcKeys.json" + ); + const { optimism: optimism_key } = require( + __dirname + "/../../config/rpcKeys.json" + ); + const { optimismsepolia: optimismsepolia_key } = require( + __dirname + "/../../config/rpcKeys.json" + ); + const networks = { 42161: { name: "arbitrum", - key: "okcKBSKXvLuSCbas6QWGvKuh-IcHHSOr", + key: arbitrum_key, }, 10: { name: "optimism", - key: "fx2SlVDrPbXwPMQT4v0lRT1PABA16Myl", + key: optimism_key, }, 11155420: { name: "optimism-sepolia", - key: "9FEqTNKmgO7X7ll92ALJrEih7Jjhldf-", + key: optimismsepolia_key, }, // other networks }; + // const { networks } = require(__dirname + "/../../config/rpcKeys.json"); const web3 = new ethers.AlchemyProvider( networks[chainId].name, networks[chainId].key diff --git a/config/rpcKeys.example.json b/config/rpcKeys.example.json new file mode 100644 index 00000000..5ac2de28 --- /dev/null +++ b/config/rpcKeys.example.json @@ -0,0 +1,4 @@ +{ + "chainName": "rpc keys", + "arbitrum": "your_rpc_key" +} From eb8be33441ad61273fd08fc27524adeb607edc3f Mon Sep 17 00:00:00 2001 From: Mahesh Murthy Date: Mon, 22 Apr 2024 16:15:31 -0700 Subject: [PATCH 3/3] Updated keys example file --- config/keys.example.json | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/config/keys.example.json b/config/keys.example.json index bbd9046f..c805ad94 100644 --- a/config/keys.example.json +++ b/config/keys.example.json @@ -1,6 +1,33 @@ { - "sepolia": "0xabc", - "optimismGoerli": "0xabc", - "gelatoKey": "l_abx_l1", - "alchemy": "alchemy provider URL" + "gapAccessToken": "", + "optimism-sepolia": { + "privateKey": "", + "rpcURL": "", + "gelatoApiKey": "", + "gapAPI": "https://gapstagapi.karmahq.xyz", + "ipfsURL": "https://gapstagapi.karmahq.xyz/ipfs" + }, + "optimism": { + "privateKey": "", + "rpcURL": "", + "gelatoApiKey": "", + "gapAPI": "https://gapapi.karmahq.xyz", + "ipfsURL": "https://gapapi.karmahq.xyz/ipfs" + }, + "arbitrum": { + "privateKey": "", + "rpcURL": "", + "gelatoApiKey": "", + "gapAPI": "https://gapapi.karmahq.xyz", + "ipfsURL": "https://gapapi.karmahq.xyz/ipfs" + }, + "sepolia": { + "privateKey": "", + "rpcURL": "", + "gelatoApiKey": "", + "gapAPI": "https://gapstagapi.karmahq.xyz", + "ipfsURL": "https://gapstagapi.karmahq.xyz/ipfs" + } + } +