Skip to content

mint

The Collector Client can be used to prepare transactions for minting 1155s, 721s, and premints with a function mint(). The type of item to mint 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.

Usage

import { 
  useChainId, 
  usePublicClient, 
  useWriteContract } from 'wagmi';
import { createCollectorClient } from "@zoralabs/protocol-sdk";
 
const chainId = useChainId();
const publicClient = usePublicClient();
 
// set to the chain you want to interact with
const collectorClient = createCollectorClient({ chainId, publicClient });
 
const { parameters } = await collectorClient.mint({
  // collection address to mint
  tokenContract: "0x1234567890123456789012345678901234567890",
  // quantity of tokens to mint
  quantityToMint: 5,
  // can be set to 1155, 721, or premint
  mintType: "
1155
721
premint
",
}); const { writeContract } = useWriteContract(); //Clicking the button writes the mint transaction to the network <button onClick={() => writeContract(parameters)}>Create</button>

Mint Premints

Once a Premint has been created and submitted to the Zora Premint API, it can be collected by calling mint() with mintType set to premint, and the uid set to the premint's uid:

example.ts
import { createCollectorClient } from "@zoralabs/protocol-sdk";
import { collection, uid } from "./createPremint";
import { useChainId, usePublicClient, useWriteContract } from "wagmi";
 
const chainId = useChainId();
const publicClient = usePublicClient()!;
 
// initialize the collect sdk with the chain configuration
const collectorClient = createCollectorClient({ chainId, publicClient });
 
// get parameters to mint a premint, which can be used to simulate and submit the transaction
const { parameters } = await collectorClient.mint({
  // the deterministic premint collection address
  tokenContract: collection,
  // type of item to mint
  mintType: "premint", 
  // the uid of the premint to mint
  uid, 
  // how many tokens to mint
  quantityToMint: 3,
  // Comment to attach to the mint
  mintComment: "Mint comment",
  // the account to execute the transaction
  minterAccount: "0xf69fEc6d858c77e969509843852178bd24CAd2B6",
});
 
const { writeContract } = useWriteContract();
 
writeContract(parameters);

Mint 1155s

1155s can be minted by calling mint() with mintType set to 1155, and the tokenId set to the token id to mint:

example.ts
import {
  useAccount,
  useChainId,
  usePublicClient,
  useWriteContract,
} from "wagmi";
import { createCollectorClient } from "@zoralabs/protocol-sdk";
 
const chainId = useChainId();
const publicClient = usePublicClient()!;
const { address } = useAccount();
 
const collectorClient = createCollectorClient({ chainId, publicClient });
 
// prepare the mint transaction
const { parameters } = await collectorClient.mint({
  // 1155 contract address
  tokenContract: "0xCD860870DE521cDb0C5ae89E80bBa057Cd30Bf8C",
  // type of item to mint
  mintType: "1155", 
  // 1155 token id to mint
  tokenId: 1n, 
  // quantity of tokens to mint
  quantityToMint: 3,
  // optional comment to include with the mint
  mintComment: "My comment",
  // optional address that will receive a mint referral reward
  mintReferral: "0x0C8596Ee50e06Ce710237c9c905D4aB63A132207",
  // account that is to invoke the mint transaction
  minterAccount: address!,
});
 
const { writeContract } = useWriteContract();
 
// write the mint transaction to the network
writeContract(parameters);

Mint ERC20 based 1155s

When minting ERC20 based 1155s, an additional approval to transfer ERC20s to an address must be executed before minting.
In the case that the 1155 to mint is an ERC20 based mint, the mint function will return an erc20Approval which contains information about which ERC20 token to approve, the amount to approve, and the address to approve to.
Before executing the mint transaction, the approval transaction must be executed:

example.ts
import { publicClient, walletClient, chainId, minterAccount } from "./config";
import { createCollectorClient } from "@zoralabs/protocol-sdk";
import { erc20Abi } from "viem";
 
const collectorClient = createCollectorClient({ chainId, publicClient });
 
// prepare the mint transaction.  If it is an erc20 based mint, the erc20Approval object will be returned
// with info for necessary erc20 approvals
const { parameters, erc20Approval } = await collectorClient.mint({
  tokenContract: "0xCD860870DE521cDb0C5ae89E80bBa057Cd30Bf8C",
  mintType: "1155",
  tokenId: 1n,
  quantityToMint: 3,
  mintComment: "My comment",
  minterAccount,
});
 
// request necessary erc20 approvals as returned from the sdk's mint call
const approveHash = await walletClient.writeContract({
  abi: erc20Abi,
  address: erc20Approval!.erc20,
  functionName: "approve",
  args: [erc20Approval!.approveTo, erc20Approval!.quantity],
  account: minterAccount,
});
 
const receipt = await publicClient.waitForTransactionReceipt({
  hash: approveHash,
});
 
if (receipt.status !== "success") {
  throw new Error("ERC20 Approval failed");
}
 
// once the erc20 approval is successful, write the mint transaction to the network
const mintHash = await walletClient.writeContract(parameters);
 
const mintReceipt = await publicClient.waitForTransactionReceipt({
  hash: mintHash,
});
 
if (mintReceipt.status !== "success") {
  throw new Error("Mint failed");
}

Mint 721s

721s can be minted by calling mint() with mintType set to 721. No tokenId is set as the token id is determined by auto-incrementing token ids; one tokenId will be created & minted for each quantityToMint:

example.ts
import { createCollectorClient } from "@zoralabs/protocol-sdk";
import { publicClient, walletClient, chainId, minterAccount } from "./config";
 
const collectorClient = createCollectorClient({ chainId, publicClient });
 
// prepare the mint transaction, which can be simulated via an rpc with the public client.
const { parameters } = await collectorClient.mint({
  // 1155 contract address
  tokenContract: "0x7aae7e67515A2CbB8585C707Ca6db37BDd3EA839",
  // type of item to mint
  mintType: "721", 
  // quantity of tokens to mint
  quantityToMint: 3,
  // optional comment to include with the mint
  mintComment: "My comment",
  // optional address that will receive a mint referral reward
  mintReferral: "0x0C8596Ee50e06Ce710237c9c905D4aB63A132207",
  // account that is to invoke the mint transaction
  minterAccount: minterAccount,
});
 
// execute the transaction
await walletClient.writeContract(parameters);

Earning Mint Referral Rewards

To earn a mint referral reward, pass in the mintReferral argument to the mint function:

example.ts
import { collection, uid } from "./createPremint";
import {
  useAccount,
  useChainId,
  usePublicClient,
  useWriteContract,
} from "wagmi";
import { createCollectorClient } from "@zoralabs/protocol-sdk";
 
const chainId = useChainId();
const publicClient = usePublicClient()!;
const { address } = useAccount();
 
const collectorClient = createCollectorClient({ chainId, publicClient });
 
const { parameters } = await collectorClient.mint({
  tokenContract: collection,
  mintType: "premint",
  uid,
  quantityToMint: 3,
  minterAccount: address!,
  // mintReferral address will get mint referral reward
  mintReferral: "0x64B585fabf03B932D637B15112cDa02C77b5cef9", 
});
 
const { writeContract } = useWriteContract();
 
writeContract(parameters);

Getting mint costs

The cost object returned from the mint() function can be used to get the costs to mint x quantity of the token.

example.ts
import { usePublicClient, useAccount } from "wagmi";
import { createCollectorClient } from "@zoralabs/protocol-sdk";
import { chainId, publicClient } from "./config";
import { tokenAddress, tokenId } from "./data";
 
const publicClient = usePublicClient();
 
const collectorClient = createCollectorClient({ chainId, publicClient });
const { address } = useAccount();
 
const { prepareMint } = await collectorClient.getToken({
  // 1155 contract address
  collection: tokenAddress,
  // 1155 token id
  tokenId,
  mintType: "
1155
721
premint
",
}); // get the costs by calling the returned `prepareMint` function // with the quantity to mint const { costs } = prepareMint({ minterAccount: address!, quantityToMint: 3n }); costs.
mintFee
totalCostEth
totalPurchaseCost
totalPurchaseCostCurrency

Parameters

import { type MakeMintParametersArguments } from "@zoralabs/protocol-sdk";
 
const params: MakeMintParametersArguments = {
  tokenContract: "0x1234567890123456789012345678901234567890",
  mintType: "1155",
  tokenId: 1n,
  minterAccount: "0x1234567890123456789012345678901234567890",
  quantityToMint: 5,
  mintReferral: "0x1234567890123456789012345678901234567890",
  mintRecipient: "0x1234567890123456789012345678901234567890",
}

tokenContract

Address

The address of the contract to mint from.

mintType

"1155" | "721" | "premint"

The type of token to mint.

tokenId

bigint (only for 1155 mints)

The token ID to mint for ERC1155 tokens.

uid

number (only for premint mints)

The unique identifier of the premint to mint.

minterAccount

Account | Address

The account that will execute the mint transaction.

quantityToMint

number | bigint

The quantity of tokens to mint. Defaults to 1.

mintComment

string (optional)

An optional comment to add to the mint transaction.

mintReferral

Address (optional)

The address that will receive the mint referral reward, if applicable.

mintRecipient

Address (optional)

The address that will receive the minted tokens. If not specified, defaults to the minting account.

firstMinter

Address (optional)

For premint mints, the address that will receive the first minter reward if this mint brings the premint onchain.

Do note that premint is a deprecated feature as we have moved to being onchain first with our mints.

allowListEntry

AllowListEntry (optional)

For allowlist mints, the information for the allowlist entry.

preferredSaleType (optional)

"fixedPrice" | "erc20" | "allowlist" | "premint" | "timed"

Optional preferred sale type of the minter to use for the token, only applicable for onchain 1155s.

Return Type

Returns an object with the following properties:

  • parameters: The parameters for the mint transaction.
  • costs: The costs for the mint transaction.