Skip to main content

Token

When using the Token smart contract, there is no need to provide a contract type argument, as the functionality of the smart contract is all available through the extensions interface.

The extensions that the Token Drop contract supports are listed below.

allowance

Get the allowance of another wallet address over the connected wallet's funds.

"Allowance" refers to the number of tokens that another wallet is allowed to spend on behalf of the connected wallet.

// Address of the wallet to check token allowance
const spenderAddress = "{{wallet_address}}";
const allowance = await contract.erc20.allowance(spenderAddress);
Configuration

spender

The address of the wallet to check the allowance of.

Must be a string.

const allowance = await contract.erc20.allowance(
"{{wallet_address}}",
);

Return Value

A CurrencyValue object is returned with the allowance available in the value property.

{
value: BigNumber;
symbol: string;
name: string;
decimals: number;
displayValue: string;
}

allowanceOf

The same as allowance, but allows you to specify the owner wallet to check, instead of using the connected wallet.

// Address of the wallet who owns the funds
const owner = "{{wallet_address}}";
// Address of the wallet to check token allowance
const spender = "{{wallet_address}}";

const allowance = await contract.erc20.allowanceOf(owner, spender);
Configuration

owner

The address of the wallet that owns the funds.

Must be a string.

const allowance = await contract.erc20.allowanceOf(
"{{wallet_address}}", // owner
"{{wallet_address}}", // spender
);

spender

The address of the wallet to check the allowance of.

Must be a string.

const allowance = await contract.erc20.allowanceOf(
"{{wallet_address}}", // owner
"{{wallet_address}}", // spender
);

Return Value

A CurrencyValue object is returned with the allowance available in the value property.

{
value: BigNumber;
symbol: string;
name: string;
decimals: number;
displayValue: string;
}

balance

View the balance (i.e. number of tokens) the connected wallet has in their wallet from this contract.

const balance = await contract.erc20.balance();
Configuration

Return Value

A CurrencyValue object is returned with the allowance available in the value property.

{
value: BigNumber;
symbol: string;
name: string;
decimals: number;
displayValue: string;
}

balanceOf

The same as balance, but allows you to specify the wallet address to check, instead of using the connected wallet.

// Address of the wallet to check token balance
const walletAddress = "{{wallet_address}}";
const balance = await contract.erc20.balanceOf(walletAddress);
Configuration

address

The address of the wallet to check the balance of.

Must be a string.

const balance = await contract.erc20.balanceOf(
"{{wallet_address}}",
);

Return Value

A CurrencyValue object is returned with the allowance available in the value property.

{
value: BigNumber;
symbol: string;
name: string;
decimals: number;
displayValue: string;
}

burn

Burn tokens held by the connected wallet.

// The amount of this token you want to burn
const amount = 1.2;

const txResult = await contract.erc20.burn(amount);
Configuration

amount

The amount of this token you want to burn.

Must be a string or a number.

const txResult = await contract.erc20.burn(
1.2, // The amount of tokens to burn (e.g. 1.2)
);

burnFrom

Burn tokens held by a specified wallet (requires allowance).

// Address of the wallet sending the tokens
const holderAddress = "{{wallet_address}}";

// The amount of this token you want to burn
const amount = 1.2;

const txResult = await contract.erc20.burnFrom(holderAddress, amount);
Configuration

holder

The address of the wallet holding to burn tokens from.

Must be a string.

const txResult = await contract.erc20.burnFrom(
"{{wallet_address}}", // The address of the wallet holding the tokens to burn
1.2, // The amount of tokens to burn (e.g. 1.2)
);

amount

The amount of this token you want to burn.

Must be a string or a number.

const txResult = await contract.erc20.burnFrom(
"{{wallet_address}}", // The address of the wallet holding the tokens to burn
1.2, // The amount of tokens to burn (e.g. 1.2)
);

generate - Signature-based

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.

const payload = {
quantity: 100, // (Required) The quantity of tokens to be minted
to: "{{wallet_address}}", // (Required) Who will receive the tokens
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
};

const signature = await contract.erc20.signature.generate(payload);
Configuration

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

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.

const signature = await contract.erc20.signature.generate({
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.

const signature = await contract.erc20.signature.generate({
quantity: "{{quantity}}",
to: "{{wallet_address}}",
});

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.erc20.signature.generate({
quantity: "{{quantity}}",
to: "{{wallet_address}}",
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.erc20.signature.generate({
quantity: "{{quantity}}",
to: "{{wallet_address}}",
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.erc20.signature.generate({
quantity: "{{quantity}}",
to: "{{wallet_address}}",
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.erc20.signature.generate({
quantity: "{{quantity}}",
to: "{{wallet_address}}",
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.erc20.signature.generate({
quantity: "{{quantity}}",
to: "{{wallet_address}}",
price: "{{price}}",
primarySaleRecipient: "{{wallet_address}}", // The funds will be sent to this address
});

generateBatch - Signature-based

Generate multiple signatures at once (see generate).

const txResult = await contract.erc20.signature.generateBatch([
{
quantity: 100, // (Required) The quantity of tokens to be minted
to: "{{wallet_address}}", // (Required) Who will receive the tokens
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, // (Required) The quantity of tokens to be minted
to: "{{wallet_address}}", // (Required) Who will receive the tokens
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
},
]);
Configuration

signatures

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

get

Get the metadata of the token smart contract, such as the name, symbol, and decimals.

const metadata = await contract.erc20.get();
Configuration

Return Value

{
symbol: string; // ticker, e.g. "ETH"
name: string; // Name of the token, e.g. "Ether"
decimals: number; // Number of decimals, e.g. 18
}

get - ContractMetadata

Get the metadata of a smart contract.

const metadata = await contract.metadata.get();
Configuration

Return Value

While the actual return type is any, you can expect an object containing properties that follow the contract level metadata standards, outlined below:

{
name: string; // Name of your smart contract
description?: string; // Short description of your smart contract
image?: string; // Image of your smart contract (any URL, or IPFS URI)
symbol?: string; // Symbol of your smart contract (ticker, e.g. "ETH")
external_link?: string; // Link to view this smart contract on your website
seller_fee_basis_points?: number // The fee you charge on secondary sales, e.g. 100 = 1% seller fee.
fee_recipient?: string; // Wallet address that receives the seller fee
}

get - Permissions

Get a list of wallet addresses that are members of a given role.

const members = await contract.roles.get("{{role_name}}");
Configuration

role

The name of the role.

Must be a string.

const members = await contract.roles.get(
"{{role_name}}",
);

Return Value

An array of strings representing the wallet addresses associated with the given role.

string[];

get - Platform Fee

Get the platform fee recipient and basis points.

const feeInfo = await contract.platformFee.get();
Configuration

Return Value

Returns an object containing the platform fee recipient and basis points.

{
platform_fee_basis_points: number;
platform_fee_recipient: string;
}

getAll - Permissions

Retrieve all of the roles and associated wallets.

const allRoles = await contract.roles.getAll();
Configuration

Return Value

An object containing role names as keys and an array of wallet addresses as the value.

<Record<any, string[]>>

getMintTransaction

Construct a mint transaction without executing it. This is useful for estimating the gas cost of a mint transaction, overriding transaction options and having fine grained control over the transaction execution.

const amount = "1.5"; // The amount of this token you want to mint
const tx = await contract.erc20.getMintTransaction(
"{{wallet_address}}", // Receiver of the tokens
amount,
);
Configuration

to

Address you want to mint the tokens to

Must be a string.

const tx = await contract.erc20.getMintTransaction(
"{{wallet_address}}",
"1.5",
);

amount

The amount of tokens you want to mint

Must be a string, number or BigNumber.

const tx = await contract.erc20.getMintTransaction(
"{{wallet_address}}", // Receiver of the tokens
"1.5",
);

Return Value

TransactionTask;

getRecipient

Get the primary sale recipient.

const salesRecipient = await contract.sales.getRecipient();
Configuration

Return Value

Returns a string containing the wallet address of the primary sale recipient.

string;

grant - Permissions

Make a wallet a member of a given role.

const txResult = await contract.roles.grant(
"{{role_name}}",
"{{wallet_address}}",
);
Configuration

role

The name of the role to grant.

Must be a string.

const txResult = await contract.roles.grant(
"{{role_name}}",
"{{wallet_address}}",
);

wallet

The wallet address to assign the role to.

Must be a string.

const txResult = await contract.roles.grant(
"{{role_name}}",
"{{wallet_address}}",
);

mint

Mint tokens to the connected wallet.

const amount = "1.5"; // The amount of this token you want to mint
const txResult = await contract.erc20.mint(amount);
Configuration

amount

The amount of tokens to mint.

Must be a string or number.

const txResult = await contract.erc20.mint(
"1.5",
);

mint - Signature-based

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

// Use the signed payload to mint the tokens
const txResult = 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
const txResult = contract.erc20.signature.mint(
signature, // Signature generated by the `generate` function
);

mintBatch

Use multiple signatures at once to mint tokens.

Each signature must be of type SignedPayload20.

const txResult = await contract.erc20.signature.mintBatch([
signature1, // Signature generated by the `generate` or `generateBatch` function
signature2,
signature3,
]);
Configuration

signatures

An array of signatures to mint. Each signature must be of type SignedPayload20.

See mint for details.

mintBatchTo

Mint tokens to many wallets in one transaction.

// Data of the tokens you want to mint
const data = [
{
toAddress: "{{wallet_address}}", // Address to mint tokens to
amount: 0.2, // How many tokens to mint to specified address
},
{
toAddress: "0x...",
amount: 1.4,
},
];

await contract.erc20.mintBatchTo(data);
Configuration

args

An array of objects containing the following properties:

  • toAddress - The address to mint tokens to. string.
  • amount - The number of tokens to mint to the specified address. string or number.
await contract.erc20.mintBatchTo(
[
{
toAddress: "{{wallet_address}}", // Address to mint tokens to
amount: 0.2, // How many tokens to mint to specified address
},
{
toAddress: "0x...", // Another address to mint tokens to
amount: 1.4, // How many tokens to mint to specified address
},
],
);

mintTo

The same as mint, but allows you to specify the address to mint the tokens to.

const toAddress = "{{wallet_address}}"; // Address of the wallet you want to mint the tokens to
const amount = "1.5"; // The amount of this token you want to mint
const txResult = await contract.erc20.mintTo(toAddress, amount);
Configuration

to

The wallet address to mint the tokens to.

Must be a string.

const txResult = await contract.erc20.mintTo(
"{{wallet_address}}",
"1.5",
);

amount

The number of tokens to mint.

Must be a string or number.

const txResult = await contract.erc20.mintTo(
"{{wallet_address}}",
"1.5",
);

normalizeAmount

Convert a number of tokens to a number of wei.

const amount = 100;
const weiAmount = await contract.erc20.normalizeAmount(amount);
Configuration

amount

The number of tokens to convert to wei.

Must be a string, number, or BigNumber.

const weiAmount = await contract.erc20.normalizeAmount(
100,
);

Return Value

A BigNumber object is returned with the amount in wei.

BigNumber;

revoke - Permissions

Revoke a given role from a wallet.

const txResult = await contract.roles.revoke(
"{{role_name}}",
"{{wallet_address}}",
);
Configuration

role

The name of the role to revoke.

Must be a string.

const txResult = await contract.roles.revoke(
"{{role_name}}",
"{{wallet_address}}",
);

wallet

The wallet address to remove the role from.

Must be a string.

const txResult = await contract.roles.revoke(
"{{role_name}}",
"{{wallet_address}}",
);

set - ContractMetadata

Overwrite the metadata of a contract, an object following the contract level metadata standards.

This operation ignores any existing metadata and replaces it with the new metadata provided.

const txResult = await contract.metadata.set({
name: "My Contract",
description: "My contract description",
});
Configuration

metadata

Provide an object containing the metadata of your smart contract following the contract level metadata standards.

{
name: string; // Name of your smart contract
description?: string; // Short description of your smart contract
image?: string; // Image of your smart contract (any URL, or IPFS URI)
symbol?: string; // Symbol of your smart contract (ticker, e.g. "ETH")
external_link?: string; // Link to view this smart contract on your website
seller_fee_basis_points?: number // The fee you charge on secondary sales, e.g. 100 = 1% seller fee.
fee_recipient?: string; // Wallet address that receives the seller fee
}

set - Platform Fee

Set the platform fee recipient and basis points.

const txResult = await contract.platformFees.set({
platform_fee_basis_points: 100,
platform_fee_recipient: "0x123",
});
Configuration

platform_fee_basis_points

The percentage fee to take, in basis points. For example, 100 basis points is 1%.

Must be a number.

platform_fee_recipient

The wallet address that will receive the platform fees.

Must be a string.

setAll - Permissions

Overwrite all roles with new members.

Dangerous Operation

This overwrites all members, INCLUDING YOUR OWN WALLET ADDRESS!

This means you can permanently remove yourself as an admin, which is non-reversible.

Please use this method with caution.

const txResult = await contract.roles.setAll({
admin: ["0x12", "0x123"],
minter: ["0x1234"],
});
Configuration

roles

An object containing role names as keys and an array of wallet addresses as the value.

const txResult = await contract.roles.setAll(
{
admin: ["0x12", "0x123"], // Grant these two wallets the admin role
minter: ["0x1234"], // Grant this wallet the minter role
},
);

setAllowance

Grant allowance to another wallet address to spend the connected wallet's funds (of this token).

// Address of the wallet to allow transfers from
const spenderAddress = "0x...";
// The number of tokens to give as allowance
const amount = 100;

await contract.erc20.setAllowance(spenderAddress, amount);
Configuration

spender

The address of the wallet to grant allowance to.

Must be a string.

await contract.erc20.setAllowance(
"{{wallet_address}}",
100,
);

amount

The number of tokens to give as allowance.

Must be a string or number.

await contract.erc20.setAllowance(
"{{wallet_address}}",
100,
);

setRecipient

Set the primary sale recipient.

await contract.sales.setRecipient("{{wallet_address}}");
Configuration

recipient

The wallet address of the primary sale recipient.

Must be a string.

totalSupply

Get the number of tokens in circulation for this contract.

const balance = await contract.erc20.totalSupply();
Configuration

Return Value

A CurrencyValue object is returned with the allowance available in the value property.

{
value: BigNumber;
symbol: string;
name: string;
decimals: number;
displayValue: string;
}

transfer

Transfer tokens from the connected wallet to another wallet.

// Address of the wallet you want to send the tokens to
const toAddress = "0x...";
// The amount of tokens you want to send
const amount = 0.1;
await contract.erc20.transfer(toAddress, amount);
Configuration

to

The address of the wallet to send the tokens to.

Must be a string.

await contract.erc20.transfer(
"{{wallet_address}}",
0.1,
);

amount

The amount of tokens to send.

Must be a string or number.

await contract.erc20.transfer(
"{{wallet_address}}",
0.1,
);

transferBatch

Transfer multiple tokens from the connected wallet to multiple wallets.

const txResult = await contract.erc20.transferBatch([
{
amount: 1,
toAddress: "0x123",
},
{
amount: 2,
toAddress: "0x456",
},
]);
Configuration
#### args

An array of objects, each containing a `toAddress` and an `amount` property.

- The `toAddress` property must be a `string`, and is the wallet address you want to send the tokens to.
- The `amount` property must be a `string`, `number`, or `BigNumber`, and is the amount of tokens you want to send to the `toAddress`

transferFrom

The same as transfer, but allows you to specify the wallet address to send the tokens from, instead of using the connected wallet.

This is only possible if the wallet initiating this transaction has been given allowance to transfer the tokens of the fromAddress.

// Address of the wallet sending the tokens
const fromAddress = "{{wallet_address}}";
// Address of the wallet you want to send the tokens to
const toAddress = "0x...";
// The number of tokens you want to send
const amount = 1.2;
// Note that the connected wallet must have approval to transfer the tokens of the fromAddress
await contract.erc20.transferFrom(fromAddress, toAddress, amount);
Configuration

from

The address of the wallet to send the tokens from.

Must be a string.

await contract.erc20.transferFrom(
"{{wallet_address}}",
"{{wallet_address}}",
1.2,
);

to

The address of the wallet to send the tokens to.

Must be a string.

await contract.erc20.transferFrom(
"{{wallet_address}}",
"{{wallet_address}}",
1.2,
);

amount

The amount of tokens to send.

Can be a number or a string.

await contract.erc20.transferFrom(
"{{wallet_address}}",
"{{wallet_address}}",
1.2,
);

update - ContractMetadata

Update the metadata of your smart contract.

const txResult = await contract.metadata.update({
name: "My Contract",
description: "My contract description",
});
Configuration

metadata

Provide an object containing the metadata of your smart contract following the contract level metadata standards.

New properties will be added, and existing properties will be overwritten. If you do not provide a new value for a previously set property, it will remain unchanged.

Below are the properties you can define on your smart contract.

{
name: string; // Name of your smart contract
description?: string; // Short description of your smart contract
image?: string; // Image of your smart contract (any URL, or IPFS URI)
symbol?: string; // Symbol of your smart contract (ticker, e.g. "ETH")
external_link?: string; // Link to view this smart contract on your website
seller_fee_basis_points?: number // The fee you charge on secondary sales, e.g. 100 = 1% seller fee.
fee_recipient?: string; // Wallet address that receives the seller fee
}

verify - Signature-based

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.

const isValid = await contract.erc20.signature.verify(
signature, // A previously generated signature
);
Configuration

signature

The signature to verify.

Must be of type SignedPayload20

See generate for details.

verify - Permissions

Check to see if a wallet has a set of roles.

Throws an error if the wallet does not have any of the given roles.

const verifyRole = await contract.roles.verify(
["admin", "minter"],
"{{wallet_address}}",
);
Configuration

roles

An array of roles to check.

Must be an array of strings.

const verifyRole = await contract.roles.verify(
["admin", "minter"],
"{{wallet_address}}",
);

wallet

The wallet address to check.

Must be a string.

const verifyRole = await contract.roles.verify(
["admin", "minter"],
"{{wallet_address}}",
);