From 21fa0ef180ceb0edffcb5c9e0ef88c5df69b909b Mon Sep 17 00:00:00 2001 From: yu23ki14 Date: Fri, 4 Oct 2024 00:26:06 +0900 Subject: [PATCH] fix --- pkgs/cli/src/commands/hats.ts | 2 +- pkgs/cli/src/modules/hatsProtocol.ts | 37 +++++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/pkgs/cli/src/commands/hats.ts b/pkgs/cli/src/commands/hats.ts index 7990722..53753a3 100644 --- a/pkgs/cli/src/commands/hats.ts +++ b/pkgs/cli/src/commands/hats.ts @@ -79,7 +79,7 @@ hatsCommands .command("createHat") .description("Create Hat") .requiredOption("-phid, --parentHatId ", "Parent Hat ID") - .requiredOption("-img, --imageURI ", "Image URI") + .option("-img, --imageURI ", "Image URI") .option("-det , --details
", "Details") .option("-max, --maxSupply ", "Max Supply") .option("-el, --eligibility ", "Eligibility Address") diff --git a/pkgs/cli/src/modules/hatsProtocol.ts b/pkgs/cli/src/modules/hatsProtocol.ts index 8097cff..da6e9fa 100644 --- a/pkgs/cli/src/modules/hatsProtocol.ts +++ b/pkgs/cli/src/modules/hatsProtocol.ts @@ -1,5 +1,5 @@ import { HatsSubgraphClient } from "@hatsprotocol/sdk-v1-subgraph"; -import { Address } from "viem"; +import { Address, decodeEventLog } from "viem"; import { base, optimism, sepolia } from "viem/chains"; import { hatsContractBaseConfig, @@ -7,6 +7,7 @@ import { } from "../config"; import { publicClient, walletClient } from ".."; import { hatIdToTreeId } from "@hatsprotocol/sdk-v1-core"; +import { startLoading } from "../services/loading"; // ############################################################### // Read with subgraph @@ -138,8 +139,10 @@ export const createHat = async (args: { eligibility?: Address; toggle?: Address; mutable?: boolean; - imageURI: string; + imageURI?: string; }) => { + const stop = startLoading(); + const { request } = await publicClient.simulateContract({ ...hatsContractBaseConfig, account: walletClient.account, @@ -151,10 +154,36 @@ export const createHat = async (args: { args.eligibility || "0x0000000000000000000000000000000000004a75", args.toggle || "0x0000000000000000000000000000000000004a75", args.mutable || true, - args.imageURI, + args.imageURI || "", ], }); - const transactionHash = walletClient.writeContract(request); + const transactionHash = await walletClient.writeContract(request); + + const receipt = await publicClient.waitForTransactionReceipt({ + hash: transactionHash, + }); + + const log = receipt.logs.find((log) => { + try { + const decodedLog = decodeEventLog({ + abi: hatsContractBaseConfig.abi, + data: log.data, + topics: log.topics, + }); + return decodedLog.eventName === "HatCreated"; + } catch (error) {} + }); + + stop(); + + if (log) { + const decodedLog = decodeEventLog({ + abi: hatsContractBaseConfig.abi, + data: log.data, + topics: log.topics, + }); + console.log(decodedLog); + } return transactionHash; };