Signature-based Minting
Functionality available for contracts that implement the
IERC721
and
ISignatureMintERC721
interfaces.
Allows you to utilize signature-based minting of NFTs.
generate
Generate a signature that a wallet address can use to mint the specified number of NFTs.
This is typically an admin operation, where the owner of the contract generates a signature that allows another wallet to mint tokens.
const payload = {
to: "{{wallet_address}}", // (Required) Who will receive the tokens
metadata: {
name: "Cool NFT #1",
description: "This is a cool NFT",
image: "https://example.com/image.png", // URL, IPFS URI, or File object
// ... Any other metadata you want to include
},
currencyAddress: "{{currency_contract_address}}", // (Optional) the currency to pay with
price: 0.5, // (Optional) the price to pay for minting those tokens (in the currency above)
mintStartTime: new Date(), // (Optional) can mint anytime from now
mintEndTime: new Date(Date.now() + 60 * 60 * 24 * 1000), // (Optional) to 24h from now,
primarySaleRecipient: "0x...", // (Optional) custom sale recipient for this token mint
quantity: 100, // (Optional) The quantity of tokens to be minted
};
const signedPayload = contract.erc721.signature.generate(payload);
Configuration
The mintRequest
object you provide to the generate
function outlines what the signature can be used for.
The to
, and metadata
fields are required, while the rest are optional.
to (required)
The wallet address that can use this signature to mint tokens.
This is to prevent another wallet from intercepting the signature and using it to mint tokens for themselves.
const signature = await contract.erc721.signature.generate({
quantity: "{{quantity}}",
to: "{{wallet_address}}",
metadata: {
// ... Your NFT metadata
},
});
metadata (required)
The metadata of the NFT to mint.
Can either be a string
URL that points to valid metadata that conforms to the metadata standards,
or an object that conforms to the same standards.
If you provide an object, the metadata is uploaded and pinned to IPFS before the NFT(s) are minted.
const signature = await contract.erc721.signature.generate({
quantity: "{{quantity}}",
to: "{{wallet_address}}",
metadata: {
name: "Cool NFT #1",
description: "This is a cool NFT",
image: "https://example.com/image.png", // URL, IPFS URI, or File object
// ... Any other metadata you want to include
},
});
uid (optional)
A unique identifier for the payload, used to prevent replay attacks and other types of exploits. Note that the input value gets hashed in the actual payload that gets generated.
The smart contract enforces on-chain that no uid gets used more than once, which means you can deterministically generate the uid to prevent specific exploits.
For example, below we use the uid
field to ensure that the user can request multiple payloads and send them to the blockchain all at once:
const balance = await contract.balance();
const signature = await contract.erc721.signature.generate({
quantity: "{{quantity}}",
to: "{{wallet_address}}",
metadata: {
// ... Your NFT metadata
},
uid: `${walletAddress}-${balance}`,
});
currencyAddress (optional)
The address of the currency to pay for minting the tokens (use the price
field to specify the price).
Defaults to NATIVE_TOKEN_ADDRESS
(the native currency of the network, e.g. Ether on Ethereum).
const signature = await contract.erc721.signature.generate({
quantity: "{{quantity}}",
to: "{{wallet_address}}",
metadata: {
// ... Your NFT metadata
},
currencyAddress: "{{currency_contract_address}}",
});
price (optional)
If you want the user to pay for minting the tokens, you can specify the price per token.
Defaults to 0
(free minting).
const signature = await contract.erc721.signature.generate({
quantity: "{{quantity}}",
to: "{{wallet_address}}",
metadata: {
// ... Your NFT metadata
},
price: "{{price}}", // The user will have to pay `price * quantity` for minting the tokens
});
mintStartTime (optional)
The time from which the signature can be used to mint tokens.
Defaults to Date.now()
(now).
const signature = await contract.erc721.signature.generate({
quantity: "{{quantity}}",
to: "{{wallet_address}}",
metadata: {
// ... Your NFT metadata
},
mintStartTime: new Date(), // The user can mint the tokens from this time
});
mintEndTime (optional)
The time until which the signature can be used to mint tokens.
Defaults to new Date(Date.now() + 1000 * 60 * 60 * 24 * 365 * 10),
(10 years from now).
const signature = await contract.erc721.signature.generate({
quantity: "{{quantity}}",
to: "{{wallet_address}}",
metadata: {
// ... Your NFT metadata
},
mintEndTime: new Date(Date.now() + 60 * 60 * 24 * 1000), // The user can mint the tokens until this time
});
primarySaleRecipient (optional)
If a price
is specified, the funds will be sent to the primarySaleRecipient
address.
Defaults to the primarySaleRecipient
address of the contract.
const signature = await contract.erc721.signature.generate({
quantity: "{{quantity}}",
to: "{{wallet_address}}",
metadata: {
// ... Your NFT metadata
},
price: "{{price}}",
primarySaleRecipient: "{{wallet_address}}", // The funds will be sent to this address
});
royaltyBps (optional)
The percentage fee you want to charge for secondary sales.
Defaults to the royaltyBps
of the contract.
const signature = await contract.erc721.signature.generate({
quantity: "{{quantity}}",
to: "{{wallet_address}}",
metadata: {
// ... Your NFT metadata
},
price: "{{price}}",
royaltyBps: 500, // A 5% royalty fee.
});
royaltyRecipient (optional)
The address that will receive the royalty fees from secondary sales.
Defaults to the royaltyRecipient
address of the contract.
const signature = await contract.erc721.signature.generate({
quantity: "{{quantity}}",
to: "{{wallet_address}}",
metadata: {
// ... Your NFT metadata
},
price: "{{price}}",
royaltyBps: 500, // A 5% royalty fee.
royaltyRecipient: "{{wallet_address}}", // The royalty fees will be sent to this address
});
quantity (optional)
The number of tokens this signature can be used to mint.
const signature = await contract.erc721.signature.generate({
quantity: "{{quantity}}",
to: "{{wallet_address}}",
metadata: {
// ... Your NFT metadata
},
});
generateBatch
Generate a batch of signatures at once.
This is the same as generate
but it allows you to generate multiple signatures at once.
const signatures = await contract.erc721.signature.generateBatch([
{
to: "{{wallet_address}}",
metadata: {
// ... Your NFT metadata
},
}
{
to: "{{wallet_address}}",
metadata: {
// ... Your NFT metadata
},
}
]);
Configuration
mint
Mint tokens from a previously generated signature (see generate
).
// Use the signed payload to mint the tokens
const txResult = contract.erc721.signature.mint(signature);
Configuration
signature (required)
The signature created by the generate
function.
The typical pattern is the admin generates a signature, and the user uses it to mint the tokens, under the conditions specified in the signature.
Must be of type SignedPayload1155
.
// Use the signed payload to mint the tokens
const txResult = contract.erc721.signature.mint(
signature, // Signature generated by the `generate` function
);
mintBatch
Use multiple signatures at once to mint tokens.
This is the same as mint
but it allows you to provide multiple signatures at once.
// Use the signed payloads to mint the tokens
const txResult = contract.erc721.signature.mintBatch(signatures);
Configuration
signatures (required)
An array of signatures created by the generate
or generateBatch
functions.
Must be of type SignedPayload1155[]
.
verify
Verify that a payload is correctly signed.
This allows you to provide a payload, and prove that it was valid and was generated by a wallet with permission to generate signatures.
If a payload is not valid, the mint
/mintBatch
functions will fail,
but you can use this function to verify that the payload is valid before attempting to mint the tokens
if you want to show a more user-friendly error message.
// Provide the generated payload to verify that it is valid
const isValid = await contract.erc721.signature.verify(payload);