Get an 1155, 721, or Premint
The Collector Client can be used to get token 1155s, 721s, and premints with
a function getToken()
. The type of token get is determined by the mintType
parameter, which
can be set to either 1155
, 721
, or premint
. Depending on the mintType
additional parameters
must be passed. The getToken()
function returns both information about the token, in the token
object, and a function
prepareMint
which takes a quantity to mint and returns the transaction parameters to mint the token, costs to mint the token, and any necessary
erc20 approvals that must be executed before minting the token.
import {
useChainId,
usePublicClient,
useAccount,
useWriteContract
} from 'wagmi';
import { createCollectorClient } from "@zoralabs/protocol-sdk";
const chainId = useChainId();
const publicClient = usePublicClient();
// initiate the collector client
const collectorClient = createCollectorClient({ chainId, publicClient });
// get the item that can be minted, and a function to prepare
// a mint transaction
const { token, prepareMint } = await collectorClient.getToken({
// contract address token belongs to
tokenContract: "0x1234567890123456789012345678901234567890",
// can be set to 1155, 721, or premint
mintType: "1155721premint",
});
// the function returns a `token` object
// containing information about the item that can be minted
token.contractcreatormaxSupplymintFeePerQuantitymintTypetokenURItotalMinted
// The `prepareMint` function can be used to prepare a transaction
// to mint x quantity of tokens to a recipient
const { address } = useAccount();
const { parameters, costs } = prepareMint({
minterAccount: address!,
quantityToMint: 3n
});
const { writeContract } = useWriteContract();
// When the button is clicked, the transaction
// to mint 3 tokens is written to the network
<button onClick={() => writeContract(parameters)}></button>
// costs to mint the 3 tokens can be retrieved
// from the returned `cost` object
costs.mintFeetotalCostEthtotalPurchaseCosttotalPurchaseCostCurrency
Minting the returned token
The getToken()
function returns a prepareMint
function that can be used to prepare a mint transaction. The prepareMint
function takes a minterAccount
and quantityToMint
parameter and returns the transaction parameters to mint the token, costs to mint the token, and any necessary erc20 approvals that must be executed before minting the token.
The returned parameters
object can be passed to a WalletClient
's writeContract
function to mint the token.
import {
useChainId,
usePublicClient,
useAccount,
useWriteContract
} from 'wagmi';
import { createCollectorClient } from "@zoralabs/protocol-sdk";
const chainId = useChainId();
const publicClient = usePublicClient()!;
const collectorClient = createCollectorClient({ chainId, publicClient });
// get the item that can be minted, and a function to prepare
// a mint transaction
const { prepareMint } = await collectorClient.getToken({
// contract address token belongs to
tokenContract: "0x1234567890123456789012345678901234567890",
// can be set to 1155, 721, or premint
mintType: "1155",
tokenId: 1n
});
// The `prepareMint` function can be used to prepare a transaction
// to mint x quantity of tokens to a recipient
const { address } = useAccount();
const { parameters, costs } = prepareMint({
minterAccount: address!,
quantityToMint: 3n
});
const { writeContract } = useWriteContract();
// When the button is clicked, the transaction
// to mint 3 tokens is written to the network
<button onClick={() => writeContract(parameters)}></button>