Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create-Community script #45

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions community/scripts/run.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
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 { 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 = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of duplicating this here, use keys.json like we use in csv-upload/script/run.ts

42161: {
name: "arbitrum",
key: arbitrum_key,
},
10: {
name: "optimism",
key: optimism_key,
},
11155420: {
name: "optimism-sepolia",
key: optimismsepolia_key,
},
// other networks
};

// const { networks } = require(__dirname + "/../../config/rpcKeys.json");
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();
35 changes: 31 additions & 4 deletions config/keys.example.json
Original file line number Diff line number Diff line change
@@ -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"
}

}

4 changes: 4 additions & 0 deletions config/rpcKeys.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"chainName": "rpc keys",
"arbitrum": "your_rpc_key"
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down