Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
yu23ki14 committed Oct 3, 2024
1 parent 102ce34 commit 21fa0ef
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkgs/cli/src/commands/hats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ hatsCommands
.command("createHat")
.description("Create Hat")
.requiredOption("-phid, --parentHatId <parentHatId>", "Parent Hat ID")
.requiredOption("-img, --imageURI <imageURI>", "Image URI")
.option("-img, --imageURI <imageURI>", "Image URI")
.option("-det , --details <details>", "Details")
.option("-max, --maxSupply <maxSupply>", "Max Supply")
.option("-el, --eligibility <eligibility>", "Eligibility Address")
Expand Down
37 changes: 33 additions & 4 deletions pkgs/cli/src/modules/hatsProtocol.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
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,
hatsTimeFrameContractBaseConfig,
} from "../config";
import { publicClient, walletClient } from "..";
import { hatIdToTreeId } from "@hatsprotocol/sdk-v1-core";
import { startLoading } from "../services/loading";

// ###############################################################
// Read with subgraph
Expand Down Expand Up @@ -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,
Expand All @@ -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;
};
Expand Down

0 comments on commit 21fa0ef

Please sign in to comment.