Skip to main content

Signature-based Minting

Functionality available for contracts that implement the ERC721 and ERC721SignatureMint extensions.

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.

from thirdweb.types.nft import NFTMetadataInput
from thirdweb.types.contracts.signature import PayloadToSign721

payload_to_sign = PayloadToSign721(
to = "{{wallet_address}}", # (Required) Who will receive the tokens
metadata = NFTMetadataInput.from_json(
"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
),
currency_address = "{{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)
mint_start_time = int(time()), # (Optional) can mint anytime from now
mint_end_time = int(time() + 60 * 60 * 24 * 1000), # (Optional) to 24h from now,
primary_sale_recipient = "0x...", # (Optional) custom sale recipient for this token mint
quantity = 100, # (Optional) The quantity of tokens to be minted
)

signed_payload = contract.erc721.signature.generate(payload)
Configuration

payload_to_sign

The payload_to_sign parameters needs to be of type PayloadToSign721

PayloadToSign721 = Signature721PayloadInput

class Signature721PayloadInput:
to: str
metadata: NFTMetadataInput
royalty_recipient: str = ZERO_ADDRESS
royalty_bps: int = 0
price: Price = 0
currency_address: str = NATIVE_TOKEN_ADDRESS
mint_start_time: int = int(time())
mint_end_time: int = int(time()) + 60 * 60 * 24 * 1000 * 1000
uid: Optional[bytes] = None
primary_sale_recipient: Optional[str] = ZERO_ADDRESS

class NFTMetadataInput:
name: str
description: Optional[str] = None
image: Optional[str] = None
external_url: Optional[str] = None
animation_url: Optional[str] = None
background_color: Optional[str] = None
properties: Optional[Dict[str, Any]] = None
attributes: Optional[Dict[str, Any]] = None

The payload_to_sign 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.

from thirdweb.types.nft import NFTMetadataInput
from thirdweb.types.contracts.signature import PayloadToSign721

signature = contract.erc721.signature.generate(PayloadToSign721(
quantity = "{{quantity}}",
to = "{{wallet_address}}",
metadata = NFTMetadataInput.from_json(
# ... 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 a PayloadToSign721 object that conforms to the same standards.

class NFTMetadataInput:
name: str
description: Optional[str] = None
image: Optional[str] = None
external_url: Optional[str] = None
animation_url: Optional[str] = None
background_color: Optional[str] = None
properties: Optional[Dict[str, Any]] = None
attributes: Optional[Dict[str, Any]] = None

If you provide a PayloadToSign721 object, the metadata is uploaded and pinned to IPFS before the NFT(s) are minted.

from thirdweb.types.nft import NFTMetadataInput
from thirdweb.types.contracts.signature import PayloadToSign721

signature = contract.erc721.signature.generate(PayloadToSign721(
quantity = 1,
to = "{{wallet_address}}",
metadata: NFTMetadataInput.from_json(
"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
),
))

currency_address (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).

from thirdweb.types.nft import NFTMetadataInput
from thirdweb.types.contracts.signature import PayloadToSign721

signature = contract.erc721.signature.generate(PayloadToSign721(
quantity = 1,
to = "{{wallet_address}}",
metadata = NFTMetadataInput.from_json(
# ... Your NFT metadata
),
currency_address = "{{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).

from thirdweb.types.nft import NFTMetadataInput
from thirdweb.types.contracts.signature import PayloadToSign721

signature = contract.erc721.signature.generate(PayloadToSign721(
quantity = 1,
to = "{{wallet_address}}",
metadata = NFTMetadataInput.from_json(
# ... Your NFT metadata
),
price = 0, # The user will have to pay `price * quantity` for minting the tokens
))

mint_start_time (optional)

The time from which the signature can be used to mint tokens.

Defaults to int(time()) (now).

from thirdweb.types.nft import NFTMetadataInput
from thirdweb.types.contracts.signature import PayloadToSign721

signature = contract.erc721.signature.generate(PayloadToSign721(
quantity = 1,
to = "{{wallet_address}}",
metadata = NFTMetadataInput.from_json(
# ... Your NFT metadata
),
mint_start_time = int(time()), # The user can mint the tokens from this time
))

mint_end_time (optional)

The time until which the signature can be used to mint tokens.

Defaults to int(time()) + 60 * 60 * 24 * 1000 * 1000 (10 years from now).

from thirdweb.types.nft import NFTMetadataInput
from thirdweb.types.contracts.signature import PayloadToSign721

signature = contract.erc721.signature.generate(PayloadToSign721(
quantity = 1,
to = "{{wallet_address}}",
metadata = NFTMetadataInput.from_json(
# ... Your NFT metadata
),
mint_end_time = int(time() + 60 * 60 * 24 * 1000), # The user can mint the tokens until this time
))

primary_sale_recipient (optional)

If a price is specified, the funds will be sent to the primary_sale_recipient address.

Defaults to the primary_sale_recipient address of the contract.

from thirdweb.types.nft import NFTMetadataInput
from thirdweb.types.contracts.signature import PayloadToSign721

signature = contract.erc721.signature.generate(PayloadToSign721(
quantity = 1,
to = "{{wallet_address}}",
metadata = NFTMetadataInput.from_json(
# ... Your NFT metadata
),
price = 0,
primary_sale_recipient = "{{wallet_address}}", # The funds will be sent to this address
))

royalty_bps (optional)

The percentage fee you want to charge for secondary sales.

Defaults to 0.

from thirdweb.types.nft import NFTMetadataInput
from thirdweb.types.contracts.signature import PayloadToSign721

signature = contract.erc721.signature.generate(PayloadToSign721(
quantity = 1,
to = "{{wallet_address}}",
metadata = NFTMetadataInput.from_json(
# ... Your NFT metadata
),
price = 0,
royalty_bps = 500, # A 5% royalty fee.
))

royalty_recipient (optional)

The address that will receive the royalty fees from secondary sales.

Defaults to the royalty_recipient address of the contract.

from thirdweb.types.nft import NFTMetadataInput
from thirdweb.types.contracts.signature import PayloadToSign721

signature = contract.erc721.signature.generate(PayloadToSign721(
quantity = 1,
to = "{{wallet_address}}",
metadata = NFTMetadataInput.from_json(
# ... Your NFT metadata
),
price = 0,
royalty_bps = 500, # A 5% royalty fee.
royalty_recipient = "{{wallet_address}}", # The royalty fees will be sent to this address
))

quantity (optional)

The number of tokens this signature can be used to mint.

Has to be of type int.

from thirdweb.types.nft import NFTMetadataInput
from thirdweb.types.contracts.signature import PayloadToSign721

signature = contract.erc721.signature.generate(PayloadToSign721(
quantity = 1,
to = "{{wallet_address}}",
metadata = NFTMetadataInput.from_json(
# ... Your NFT metadata
),
))

generate_batch

Generate a batch of signatures at once.

This is the same as generate but it allows you to generate multiple signatures at once.

from thirdweb.types.nft import NFTMetadataInput
from thirdweb.types.contracts.signature import PayloadToSign721

signatures = contract.erc721.signature.generateBatch([
PayloadToSign721(
to = "{{wallet_address}}",
metadata = NFTMetadataInput.from_json(
# ... Your NFT metadata
),
)
PayloadToSign721(
to = "{{wallet_address}}",
metadata = NFTMetadataInput.from_json(
# ... Your NFT metadata
),
)
])
Configuration

payloads_to_sign

A list of PayloadToSign721 objects containing the configuration options for each signature.

See generate for the configuration options available for each signature.

mint

Mint tokens from a previously generated signature (see generate).

# Use the signed payload to mint the tokens
tx = 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 SignedPayload721.

# Use the signed payload to mint the tokens
tx = contract.erc721.signature.mint(
signature # Signature generated by the `generate` function
)

mint_batch

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
tx = contract.erc721.signature.mint_batch(signatures)
Configuration

signatures (required)

A list of signatures created by the generate or generateBatch functions.

Must be of type List[SignedPayload721].

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/mint_batch 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
is_valid = contract.erc721.signature.verify(payload)
Configuration

payload (required)

The payload to verify.

Must be of type SignedPayload721.

Return Value

Returns a bool: true if the payload is valid, false otherwise.