Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
iainnash committed Nov 30, 2023
1 parent b3b2704 commit 0c0b330
Showing 1 changed file with 7 additions and 26 deletions.
33 changes: 7 additions & 26 deletions packages/protocol-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,11 @@ async function mintNFT({
}) {
const mintClient = createMintClient({chain: walletClient.chain!});

// get mintable information about the token.
const mintable = await mintClient.getMintable({
tokenContract,
tokenId,
});

// prepare the mint transaction, which can be simulated via an rpc with the public client.
const prepared = await mintClient.makePrepareMintTokenParams({
// token to mint
mintable,
tokenContract,
tokenId,
mintArguments: {
// address that will receive the token
mintToAddress,
Expand Down Expand Up @@ -81,7 +76,7 @@ async function mintNFT({
#### Using wagmi

```tsx
import {createMintClient, Mintable} from "@zoralabs/protocol-sdk";
import {createMintClient} from "@zoralabs/protocol-sdk";
import {useEffect, useMemo, useState} from "react";
import {BaseError, SimulateContractParameters, stringify} from "viem";
import {Address, useAccount, useContractWrite, useNetwork, usePrepareContractWrite, usePublicClient, useWaitForTransaction} from "wagmi";
Expand All @@ -104,33 +99,19 @@ export const Mint = ({tokenId, tokenContract}: {tokenId: string; tokenContract:
// value will be set by the form
const [quantityToMint, setQuantityToMint] = useState<number>(1);

// fetched mintable info from the sdk
const [mintable, setMintable] = useState<Mintable>();

useEffect(() => {
// fetch the mintable token info
const fetchMintable = async () => {
if (mintClient) {
const mintable = await mintClient.getMintable({tokenId, tokenContract});
setMintable(mintable);
}
};

fetchMintable();
}, [mintClient, tokenId, tokenContract]);

// params for the prepare contract write hook
const [params, setParams] = useState<SimulateContractParameters>();

const {address} = useAccount();

useEffect(() => {
if (!mintable || !mintClient || !address) return;
if (!mintClient || !address) return;

const makeParams = async () => {
// make the params for the prepare contract write hook
const params = await mintClient.makePrepareMintTokenParams({
mintable,
tokenId,
tokenContract,
minterAccount: address,
mintArguments: {
mintToAddress: address,
Expand All @@ -141,7 +122,7 @@ export const Mint = ({tokenId, tokenContract}: {tokenId: string; tokenContract:
};

makeParams();
}, [mintable, mintClient, address, quantityToMint]);
}, [mintClient, address, quantityToMint]);

const {config} = usePrepareContractWrite(params);

Expand Down

0 comments on commit 0c0b330

Please sign in to comment.