Skip to main content

ERC20SignatureMintable

Functionality available for contracts that implement the ERC20 and ERC20SignatureMint extensions.

Allows you to utilize signature-based minting of new tokens.

generate

Generate a signature that a wallet address can use to mint the specified number of tokens.

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.contracts.signature import PayloadToSign20
mint_request = PayloadToSign20(
to = "{{wallet_address}}",
price = 0.5,
currency_address = "{{currency_contract_address}}",
primary_sale_address = "{{primary_sale_address}}",
quantity = 100,
mint_start_time = int(time() + 60 * 60 * 24),
mint_end_time = int(time()) - 1800,
uid = None)

good_payload = token.signature.generate(mint_request)
Configuration

mint_request

The mint_request object you provide to the generate function outlines what the signature can be used for.

It must be of type PayloadToSign20

PayloadToSign20 = Signature20PayloadInput

class Signature20PayloadInput(BaseSignaturePayloadInput):
quantity: Price = 0

class BaseSignaturePayloadInput:
to: str
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

The quantity and to fields are required, while the rest are optional.

quantity (required)

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

from thirdweb.types.contracts.signature import PayloadToSign20

quantity = 1
signature = contract.erc20.signature.generate(PayloadToSign20(
quantity = quantity,
to = "{{wallet_address}}"))

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.contracts.signature import PayloadToSign20

quantity = 1
to = "0x..."
signature = contract.erc20.signature.generate(PayloadToSign20(
quantity = quantity,
to = to))

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.contracts.signature import PayloadToSign20

quantity = 1
to = "0x..."
currency_address = "0x..."
signature = contract.erc20.signature.generate(PayloadToSign20(
quantity = quantity,
to = to,
currency_address = currency_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).

Needs to be of type float.

from thirdweb.types.contracts.signature import PayloadToSign20

quantity = 1
to = "0x..."
price = 0.4
signature = contract.erc20.signature.generate(PayloadToSign20(
quantity = quantity,
to = to,
price = price))

mint_start_time (optional)

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

Defaults to time() (now).

from thirdweb.types.contracts.signature import PayloadToSign20

quantity = 1
to = "0x..."
mint_start_time = int(time() + 5)
signature = contract.erc20.signature.generate(PayloadToSign20(
quantity = quantity,
to = to,
mint_start_time = mint_start_time))

mint_end_time (optional)

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

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

from thirdweb.types.contracts.signature import PayloadToSign20

quantity = 1
to = "0x..."
mint_end_time = int(time() * 60 * 60 * 24 * 365 * 10)
signature = contract.erc20.signature.generate(PayloadToSign20(
quantity = quantity,
to = to,
mint_end_time = mint_end_time))

primary_sale_recipient (optional)

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

Defaults to the primary_sale_recipient address of the contract.

from thirdweb.types.contracts.signature import PayloadToSign20

quantity = 1
to = "0x..."
price = 0.4
primary_sale_recipient = "0x..."
signature = contract.erc20.signature.generate(PayloadToSign20(
quantity = quantity,
to = to,
price = price,
primary_sale_recipient = primary_sale_recipient))

generate_batch

Generate multiple signatures at once (see generate).

from thirdweb.types.contracts.signature import PayloadToSign20

tx = contract.erc20.signature.generate_batch([
PayloadToSign20(
quantity = 100, # (Required) The quantity of tokens to be minted
to = "{{wallet_address}}", # (Required) Who will receive the tokens
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
),
PayloadToSign20(
quantity = 100, # (Required) The quantity of tokens to be minted
to = "{{wallet_address}}", # (Required) Who will receive the tokens
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
)
])
Configuration

signatures

An array of signatures to generate. See generate for details.

mint

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

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

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

mint_batch

Use multiple signatures at once to mint tokens.

Each signature must be of type SignedPayload20 and be privided in a List.

tx = contract.erc20.signature.mint_batch([
signature1, # Signature generated by the `generate` or `generateBatch` function
signature2,
signature3,
])
Configuration

signatures

A list of signatures to mint. Each signature must be of type SignedPayload20.

class SignedPayload20:
payload: Signature20PayloadInput
signature: str

class Signature20PayloadInput(BaseSignaturePayloadInput):
quantity: Price = 0

class BaseSignaturePayloadInput:
to: str
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

See mint for details.

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 (even without this verification check), 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.

is_valid = contract.erc20.signature.verify(
signature, # A previously generated signature
)
Configuration

signature

The signature to verify.

Must be of type SignedPayload20

See generate for details.