Skip to main content

ERC20 Standard Functionality

Using ERC20 features lets you add standard ERC20 compliant token functionality to your contracts. These interfaces can give your contract simple read-only functionality as well as more complex features like token minting and transfers.

We support a number of different ERC20 features on your contracts that enable different SDK and dashboard functionality. Let's explore all the options below!

ERC20

The most standard ERC20 interface, which is often considered the default and is implemented by most ERC20 tokens, is the EIP-20 standard.

If your contract, implements all the functions in this standard, you will get support for all of the following functions in the SDK.

Setup

You can get an initial instance for your contract with the following code:

const contract = await sdk.getContract("{{contract_address}}");
await contract.token.transfer(walletAddress, amount);
View in Javascript SDK Documentation

allowance

Get Token Allowance

// Address of the wallet to check token allowance
const spenderAddress = "0x...";
const allowance = await contract.token.allowance(spenderAddress);
View in Javascript SDK Documentation

allowanceOf

Get Token Allowance

// Address of the wallet who owns the funds
const owner = "{{wallet_address}}";
// Address of the wallet to check token allowance
const spender = "0x...";
const allowance = await contract.token.allowanceOf(owner, spender);
View in Javascript SDK Documentation

balance

Get Token Balance for the currently connected wallet

const balance = await contract.token.balance();
View in Javascript SDK Documentation

balanceOf

Get Token Balance

// Address of the wallet to check token balance
const walletAddress = "{{wallet_address}}";
const balance = await contract.token.balanceOf(walletAddress);
View in Javascript SDK Documentation

get

Get the token Metadata (name, symbol, etc...)

const token = await contract.token.get();
View in Javascript SDK Documentation

setAllowance

Allows the specified `spender` wallet to transfer the given `amount` of tokens to another wallet

// Address of the wallet to allow transfers from
const spenderAddress = "0x...";
// The number of tokens to give as allowance
const amount = 100
await contract.token.setAllowance(spenderAddress, amount);
View in Javascript SDK Documentation

totalSupply

The total supply for this Token

const balance = await contract.token.totalSupply();
View in Javascript SDK Documentation

transfer

Transfer Tokens

// 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.token.transfer(toAddress, amount);
View in Javascript SDK Documentation

transferBatch

Transfer Tokens To Many Wallets

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

await contract.token.transferBatch(data);
View in Javascript SDK Documentation

transferFrom

Transfer Tokens From Address

// 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.token.transferFrom(fromAddress, toAddress, amount);
View in Javascript SDK Documentation

Extensions

In addition to the standard ERC20 interface, we also support the following additional ERC20 features which you can add onto your contract.

info

In order to use these features, the contract must also implement the standard ERC20 interface as well.

ERC20Mintable

The ERC20Mintable interface enables you to add minting functionality to your tokens. You can add this interface to your contract by implementing all of the functions in the IMintableERC20 interface as shown below:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import "@thirdweb-dev/contracts/feature/interface/IMintableERC20.sol";

// We add the interface to the contract
contract MyCustomContract is IMintableERC20 {

function mintTo(address to, uint256 amount) external override returns (uint256) {
// implement your mint function
}
}

If your contract implements all the functions in this standard, you will get support for the following functions in the SDK.

Setup
const contract = await sdk.getContract("{{contract_address}}");
await contract.nft.mint.to(walletAddress, nftMetadata);
View in Javascript SDK Documentation

to

Mint Tokens

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
await contract.token.mint.to(toAddress, amount);
View in Javascript SDK Documentation

ERC20BatchMintable

The ERC20BatchMintable interface enables you to add batch minting functionality to your tokens. You can add this interface to your contract by implementing all of the functions in the IMintableERC20 and IMulticall interfaces as shown below:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import "@thirdweb-dev/contracts/feature/interface/IMintableERC20.sol";
import "@thirdweb-dev/contracts/feature/interface/IMulticall.sol";

// We add the interface to the contract
contract MyCustomContract is IMintableERC20, IMulticall {

function mintTo(address to, uint256 amount) external override returns (uint256) {
// implement your mint function
}

function multicall(bytes[] data) external override returns (bytes[] results) {
// you can use any standard multicall implementation here
}
}

If your contract implements all the functions in this standard, you will get support for the following functions in the SDK.

Setup
const contract = await sdk.getContract("{{contract_address}}");
await contract.token.mint.batch.to(walletAddress, [nftMetadata1, nftMetadata2, ...]);
View in Javascript SDK Documentation

to

Mint Tokens To Many Wallets

// 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.mintBatchTo(data);
View in Javascript SDK Documentation