diff --git a/pkgs/cli/package.json b/pkgs/cli/package.json index 4bfc65f..e318d47 100644 --- a/pkgs/cli/package.json +++ b/pkgs/cli/package.json @@ -16,9 +16,11 @@ "@hatsprotocol/sdk-v1-subgraph": "^1.0.0", "commander": "^12.1.0", "dotenv": "^16.4.5", + "pinata-web3": "^0.5.0", "ts-node": "^10.9.2", "typescript": "^5.6.2", - "viem": "^2.21.15" + "viem": "^2.21.15", + "zod": "^3.23.8" }, "devDependencies": { "@types/commander": "^2.12.2", diff --git a/pkgs/cli/src/commands/hats.ts b/pkgs/cli/src/commands/hats.ts index 583ee1f..7990722 100644 --- a/pkgs/cli/src/commands/hats.ts +++ b/pkgs/cli/src/commands/hats.ts @@ -6,6 +6,7 @@ import { createHat, mintHat, } from "../modules/hatsProtocol"; +import { PinataSDK } from "pinata-web3"; import { getAccount } from "../services/wallet"; import { publicClient, rootProgram, walletClient } from ".."; import { Address } from "viem"; @@ -33,8 +34,9 @@ hatsCommands .description("Show all of the Hats that are associated with the tree ID") .option("-id, --treeId ", "Tree ID") .action(async (options) => { + const { chain } = rootProgram.opts(); // ツリー情報を全て取得する。 - const tree = await getTreeInfo(Number(options.treeId), options.chainId); + const tree = await getTreeInfo(Number(options.treeId), chain); console.log(tree); }); @@ -47,8 +49,9 @@ hatsCommands .description("Show all of the wears that are associated with the hat ID") .option("-id, --hatId ", "Hat ID") .action(async (options) => { + const { chain } = rootProgram.opts(); // ツリー情報を全て取得する。 - const wearers = await getWearersInfo(options.hatId, options.chainId); + const wearers = await getWearersInfo(options.hatId, chain); console.log(wearers); }); @@ -75,16 +78,16 @@ hatsCommands hatsCommands .command("createHat") .description("Create Hat") - .requiredOption("-hid", "--hatId ", "Hat ID") - .requiredOption("-img", "--imageUri ", "Image URI") - .option("-det", "--details
", "Details") - .option("-max", "--maxSupply ", "Max Supply") - .option("-el", "--eligibility ", "Eligibility Address") - .option("-tgl", "--toggle ", "Toggle") - .option("-mut", "--mutable ", "Mutable") + .requiredOption("-phid, --parentHatId ", "Parent Hat ID") + .requiredOption("-img, --imageURI ", "Image URI") + .option("-det , --details
", "Details") + .option("-max, --maxSupply ", "Max Supply") + .option("-el, --eligibility ", "Eligibility Address") + .option("-tgl, --toggle ", "Toggle") + .option("-mut, --mutable ", "Mutable") .action( async ({ - hatId, + parentHatId, details, maxSupply, eligibility, @@ -92,15 +95,17 @@ hatsCommands mutable, imageURI, }) => { - await createHat({ - parentHatId: BigInt(hatId), + const transactionHash = await createHat({ + parentHatId: BigInt(parentHatId), details, maxSupply, eligibility: eligibility as Address, toggle: toggle as Address, - mutable: mutable, + mutable: mutable == "true", imageURI, }); + + console.log("Transaction hash: ", transactionHash); } ); @@ -110,8 +115,10 @@ hatsCommands hatsCommands .command("mintHat") .description("Mint Hat") - .requiredOption("-hid", "--hatId ", "Hat ID") + .requiredOption("-hid, --hatId ", "Hat ID") .requiredOption("--wearer ", "Wearer address") .action(async ({ hatId, wearer }) => { - await mintHat({ hatId, wearer }); + const transactionHash = await mintHat({ hatId, wearer }); + + console.log("Transaction hash: ", transactionHash); }); diff --git a/pkgs/cli/src/commands/pinata.ts b/pkgs/cli/src/commands/pinata.ts new file mode 100644 index 0000000..41c99cf --- /dev/null +++ b/pkgs/cli/src/commands/pinata.ts @@ -0,0 +1,111 @@ +import { Command } from "commander"; +import { getJwt, setJwt } from "../services/pinata"; +import { PinataSDK } from "pinata-web3"; + +export const pinataCommands = new Command(); + +// ############################################################### +// CLI init setup +// ############################################################### + +pinataCommands + .name("pinata") + .description("This is a CLI for pinata") + .version("1.0.0"); + +/** + * PinataのJWTを設定するコマンド + */ +pinataCommands + .command("setJwt") + .description("Set a jwt of Pinata") + .requiredOption("--jwt ") + .action(({ jwt }) => { + setJwt(jwt); + }); + +/** + * Hatのメタデータをipfs上にアップロードするコマンド + */ +interface Responsibility { + label: string; + description?: string; + link?: string; +} +interface Eligibility { + manual: boolean; + criteria: string[]; +} +interface Toggle { + manual: boolean; + criteria: string[]; +} + +pinataCommands + .command("uploadMetadata") + .description("Upload the hat metadata on ipfs.") + .requiredOption("-n, --name ", "Hat Name") + .requiredOption("-d, --description ", "Hat Details") + .option( + "-r, --responsibilities