diff --git a/examples/create-guild-profile/index.ts b/examples/create-guild-profile/index.ts new file mode 100644 index 0000000..ca2843c --- /dev/null +++ b/examples/create-guild-profile/index.ts @@ -0,0 +1,60 @@ +/** + * Create Guild Profile — BeatinDaBlock Podcast + * + * This example demonstrates how to create a guild profile for the + * "BeatinDaBlock" podcast using the Guild SDK. + * + * Usage: + * PRIVATE_KEY= npm start + */ + +import { createGuildClient, createSigner } from "@guildxyz/sdk"; +import { Wallet } from "ethers"; + +// --------------------------------------------------------------------------- +// Main +// --------------------------------------------------------------------------- + +async function main() { + // Resolve the private key from the environment, or fall back to a random + // wallet for demonstration purposes. + const privateKey = process.env.PRIVATE_KEY; + const wallet = privateKey ? new Wallet(privateKey) : Wallet.createRandom(); + + console.log(`Using wallet: ${wallet.address}`); + + const client = createGuildClient("beatindablock-guild-setup"); + const signer = createSigner.fromEthersWallet(wallet, { + msg: "Create my Guild profile", + }); + + console.log('\nCreating guild: "BeatinDaBlock"'); + + const created = await client.guild.create( + { + name: "BeatinDaBlock", + urlName: "beatindablock", + description: + "The official community for BeatinDaBlock — a podcast covering hip-hop culture, music production, and the intersection of beats and blockchain.", + contacts: [], + // Free-to-join listener role so any fan can get access right away. + roles: [ + { + name: "Listener", + requirements: [{ type: "FREE" }], + }, + ], + }, + signer + ); + + console.log("Guild created successfully!"); + console.log(` id : ${created.id}`); + console.log(` urlName : ${created.urlName}`); + console.log(` url : https://guild.xyz/${created.urlName}`); +} + +main().catch((err) => { + console.error(err); + process.exit(1); +}); diff --git a/examples/create-guild-profile/package.json b/examples/create-guild-profile/package.json new file mode 100644 index 0000000..ae80268 --- /dev/null +++ b/examples/create-guild-profile/package.json @@ -0,0 +1,18 @@ +{ + "name": "create-guild-profile", + "version": "0.1.0", + "private": true, + "type": "module", + "scripts": { + "start": "npx ts-node --esm index.ts" + }, + "dependencies": { + "@guildxyz/sdk": "^2.6.8", + "ethers": "^6.7.1" + }, + "devDependencies": { + "@types/node": "latest", + "ts-node": "^10.9.1", + "typescript": "^5.2.2" + } +} diff --git a/examples/create-guild-profile/tsconfig.json b/examples/create-guild-profile/tsconfig.json new file mode 100644 index 0000000..076ef81 --- /dev/null +++ b/examples/create-guild-profile/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "target": "ESNext", + "module": "ESNext", + "moduleResolution": "node", + "esModuleInterop": true, + "strict": true, + "skipLibCheck": true, + "outDir": "dist" + }, + "include": ["index.ts"] +}