ERC20 Standard Features
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.
SetupYou can get an initial instance for your contract with the following code:
- Javascript
const contract = await sdk.getContract("{{contract_address}}");
await contract.token.transfer(walletAddress, amount);
allowance
Get Token Allowance
- Javascript
// Address of the wallet to check token allowance
const spenderAddress = "0x...";
const allowance = await contract.token.allowance(spenderAddress);
allowanceOf
Get Token Allowance
- Javascript
// 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);
balance
Get Token Balance for the currently connected wallet
- Javascript
const balance = await contract.token.balance();
balanceOf
Get Token Balance
- Javascript
// Address of the wallet to check token balance
const walletAddress = "{{wallet_address}}";
const balance = await contract.token.balanceOf(walletAddress);
get
Get the token Metadata (name, symbol, etc...)
- Javascript
const token = await contract.token.get();
setAllowance
Allows the specified `spender` wallet to transfer the given `amount` of tokens to another wallet
- Javascript
// 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);
totalSupply
The total supply for this Token
- Javascript
const balance = await contract.token.totalSupply();
transfer
Transfer Tokens
- Javascript
// 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);
transferBatch
Transfer Tokens To Many Wallets
- Javascript
// 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);
transferFrom
Transfer Tokens From Address
- Javascript
// 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);
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/ThirdwebContract.sol";
import "@thirdweb-dev/contracts/feature/interface/IMintableERC20.sol";
// We add the interface to the contract
contract MyCustomContract is ThirdwebContract, IMintableERC20 {
function mintTo(address to, uint256 amount) external 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- Javascript
const contract = await sdk.getContract("{{contract_address}}");
await contract.nft.mint.to(walletAddress, nftMetadata);
to
Mint Tokens
- Javascript
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);
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/ThirdwebContract.sol";
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 ThirdwebContract, IMintableERC20, IMulticall {
function mintTo(address to, uint256 amount) external returns (uint256) {
// implement your mint function
}
function multicall(bytes[] data) external nonpayable 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- Javascript
const contract = await sdk.getContract("{{contract_address}}");
await contract.token.mint.batch.to(walletAddress, [nftMetadata1, nftMetadata2, ...]);
to
Mint Tokens To Many Wallets
- Javascript
// 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);