Custom Contracts
Using your own Custom Contract on Polygon, Ethereum, or another EVM blockchain? The following example shows you how to use it with thirdweb.
Example
Assume that this is your contract's claim function:
You will then need a mintMethod in order for thirdweb to call your claim function. For the example above, your mintMethod should look like this:
This will ensure that when thirdweb calls the smart contract during any checkout flow, under the hood, we would be calling your smart contract like so:
Requirements
Your smart contract method that mints the NFT must satisfy these requirements:
- The method must accept the buyer's wallet address as an argument.
- The method must allow thirdweb's minter wallets to mint an unlimited amount as the
msg.sender
. Any restrictions on the minting wallet address or quantity is not allowed. - (If priced in USDC) The method must explicitly request USDC token from the
msg.sender
.
MintMethod
The mintMethod is required when creating Shareable Checkout Links, One-Time Checkout Links, or Checkout Elements. Think of it as an ABI for thirdweb to know how to call your claim function.
The generic format of the mintMethod is:
Template variables
🚧 Don't know the values?
thirdweb supports two template variables -
$WALLET
and$QUANTITY
that you may use if you don't know the buyer's wallet address and quantity. Note that for all other fields such asvalue
andcurrency
, you would need to hardcode the actual values.
Template variables will be replaced when calling your contract:
Payment
The payment
field should provide the price per NFT in human-readable form (not wei).
Example: "payment": { "value": "0.1 * $QUANTITY", "currency": "ETH" }
Free NFTs
Set the price to zero.
Example: "payment": { value: "0 * $QUANTITY", currency: "MATIC" }
NFTs priced in USDC
Ensure your mint method explicitly requests USDC tokens from msg.sender. See USDC Pricing for more details.
Delegate a different ERC-20 payment address
📘 This is required when interacting with the Seaport contract.
By default thirdweb's float wallet approves your NFT contract to request ERC-20 tokens.
To specify a different contract address that will request ERC-20 tokens from thirdweb's float wallet, set that address in the "spender"
field:
FAQ
I have multiple methods with the same name. Why isn't my mintMethod isn't working?
Please provide the full signature as your mintMethod. thirdweb will not try to "guess" the correct method.
Example
Your contract has methods
mint(address to)
andmint(address to, string tokenId)
and your checkout will call the former.Provide your mintMethod as
mint(address)
.
You do not need to modify your contract.