Token
The Token contract is suited for projects in which you want to create your own currency. This currency can be purchased and traded between users on an exchange, utilized to buy and sell NFTs in a marketplace, and much more.
The Token contract is compliant with the ERC20 standard.
You could use the Token contract to:
- Create your own cryptocurrency
- Sell your NFTs on the Marketplace in your custom token
- Reward users with tokens for some action they take
Create a Token Contract
Learn how to create any of thirdweb's pre-built contracts in the Deploying Contracts page.
Getting the contract in your application
To start using your Token contract inside your application, you'll need to use it's contract address. You can get the contract address from the dashboard.
- Javascript
- React
- Python
- Go
import { ThirdwebSDK } from "@thirdweb-dev/sdk";
const sdk = new ThirdwebSDK("rinkeby");
const contract = sdk.getToken("{{contract_address}}");
import { useToken } from '@thirdweb-dev/react'
export default function Component() {
const token = useToken("<YOUR-CONTRACT-ADDRESS>")
// Now you can use the token contract in the rest of the component
}
from thirdweb import ThirdwebSDK
from eth_account import Account
# You can customize this to a supported network or your own RPC URL
network = "mumbai"
# This will create a random account to use for signing transactions
signer = Account.create()
sdk = ThirdwebSDK(network, signer)
contract = sdk.get_token("{{contract_address}}")
import (
"github.com/thirdweb-dev/go-sdk/thirdweb"
)
privateKey = "..."
sdk, err := thirdweb.NewThirdwebSDK("mumbai", &thirdweb.SDKOptions{
PrivateKey: privateKey,
})
contract, err := sdk.GetToken("{{contract_address}}")
Minting Tokens
Using the dashboard
You can mint new tokens on the dashboard by clicking the Mint button.
Using the SDK
Mint tokens to a specified wallet
- Javascript
- React
- Python
- Go
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.mintTo(toAddress, amount);
React SDK support for mintTo is coming soon.
Want this feature sooner? Let us know in Discord!
contract.mint_to("{{wallet_address}}", 1)
tx, err := contract.MintTo("{{wallet_address}}", 1)
Mint tokens to many wallets in one transaction (batch)
- Javascript
- React
- Python
- Go
// 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);
React SDK support for mintBatchTo is coming soon.
Want this feature sooner? Let us know in Discord!
from thirdweb.types.currency import TokenAmount
args = [
TokenAmount("{{wallet_address}}", 1),
TokenAmount("{{wallet_address}}", 2),
]
contract.mint_batch_to(args)
args = []*thirdweb.TokenAmount{
&thirdweb.TokenAmount{
ToAddress: "{{wallet_address}}",
Amount: 1
}
&thirdweb.TokenAmount{
ToAddress: "{{wallet_address}}",
Amount: 2
}
}
tx, err := contract.MintBatchTo(args)
Token Metadata
Get the metadata about the token itself, such as the name, symbol, and decimals.
- Javascript
- React
- Python
- Go
const token = await contract.token.get();
React SDK support for get is coming soon.
Want this feature sooner? Let us know in Discord!
token = contract.get()
print(token)
currency, err := contract.Get()
symbol := currency.Symbol
You can get the total supply of the token too.
- Javascript
- React
- Python
- Go
const balance = await contract.token.totalSupply();
React SDK support for totalSupply is coming soon.
Want this feature sooner? Let us know in Discord!
Python SDK support for totalSupply is coming soon.
Want this feature sooner? Let us know in Discord!
Go SDK support for totalSupply is coming soon.
Want this feature sooner? Let us know in Discord!
Token Balance
Balance of the connected wallet
- Javascript
- React
- Python
- Go
const balance = await contract.token.balance();
React SDK support for balance is coming soon.
Want this feature sooner? Let us know in Discord!
balance = contract.balance()
print(balance)
balance, err := contract.Balance()
Balance of a specified wallet
- Javascript
- React
- Python
- Go
// Address of the wallet to check token balance
const walletAddress = "{{wallet_address}}";
const balance = await contract.token.balanceOf(walletAddress);
React SDK support for balanceOf is coming soon.
Want this feature sooner? Let us know in Discord!
address = "{{wallet_address}}"
balance = contract.balance_of(address)
print(balance)
address := "{{wallet_address}}"
balance, err := contract.BalanceOf()
Token Allowance
Allowance refers to how many tokens another address is allowed to spend from your wallet.
For example, our Marketplace contract asks you permission to increase your allowance when you make a bid on an auction listing.
Get allowance for the connected wallet
Get the amount of tokens that another wallet is allowed to spend on behalf of the connected wallet.
- Javascript
- React
- Python
- Go
// Address of the wallet to check token allowance
const spenderAddress = "0x...";
const allowance = await contract.token.allowance(spenderAddress);
React SDK support for allowance is coming soon.
Want this feature sooner? Let us know in Discord!
spender = "{{wallet_address}}"
allowance = contract.allowance(spender)
spender := "0x..."
allowance, err := contract.Allowance(spender)
allowanceValue := allowance.DisplayValue
Get allowance for a specified wallet
Get the amount of tokens that another wallet is allowed to spend on behalf of the specified wallet.
- Javascript
- React
- Python
- Go
// 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);
React SDK support for allowanceOf is coming soon.
Want this feature sooner? Let us know in Discord!
# Address of the wallet who owns the funds
address = "{{wallet_address}}"
# Address of the wallet to check the token allowance
spender = "0x..."
allowance = contract.allowance_of(address, spender)
print(allowance)
address := "{{wallet_address}}"
spender := "0x..."
allowance, err := contract.AllowanceOf(address, spender)
allowanceValue := allowance.DisplayValue
Set Allowance
Specify how many tokens another wallet is allowed to spend on behalf of the connected wallet.
- Javascript
- React
- Python
- Go
// 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);
React SDK support for setAllowance is coming soon.
Want this feature sooner? Let us know in Discord!
spender = "0x..."
amount = 100
contract.set_allowance(spender, amount)
spender := "0x..."
amount := 1
tx, err := contract.SetAllowance(spender, amount)
Transfer Tokens
You can transfer tokens from one wallet to another, or send tokens to a smart contract address.
Transfer from the connected wallet
- Javascript
- React
- Python
- Go
// 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);
React SDK support for transfer is coming soon.
Want this feature sooner? Let us know in Discord!
# Address to send tokens to
to = "0x...
# Amount of tokens to transfer
amount = 0.1
contract.transfer(to, amount)
to := "0x..."
amount := 1
tx, err := contract.Transfer(to, amount)
Transfer from the connected wallet in batch
- Javascript
- React
- Python
- Go
// 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);
React SDK support for transferBatch is coming soon.
Want this feature sooner? Let us know in Discord!
from thirdweb.types.currency import TokenAmount
data = [
TokenAmount("{{wallet_address}}", 0.1),
TokenAmount("0x...", 0.2),
]
contract.transfer_batch(data)
args = []*thirdweb.TokenAmount{
&thirdweb.TokenAmount{
ToAddress: "0x...",
Amount: 1
}
&thirdweb.TokenAmount{
ToAddress: "0x...",
Amount: 2
}
}
tx, err := contract.TransferBatch(args)
Transfer from a specified wallet
- Javascript
- React
- Python
- Go
// 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);
React SDK support for transferFrom is coming soon.
Want this feature sooner? Let us know in Discord!
# Address to send tokens from
fr = "{{wallet_address}}"
# Address to send tokens to
to = "0x..."
# Amount of tokens to transfer
amount = 0.1
contract.transfer_from(fr, to, amount)
from := "{{wallet_address}}"
to := "0x..."
amount := 1
tx, err := contract.TransferFrom(from, to, amount)
Burning Tokens
Burning tokens takes a specified amount of tokens out of the circulating supply.
Burn from the connected wallet
- Javascript
- React
- Python
- Go
// The amount of this token you want to burn
const amount = 1.2;
await contract.burn(amount);
React SDK support for burn is coming soon.
Want this feature sooner? Let us know in Discord!
amount = 0.1
contract.burn(amount)
amount := 1
tx, err := contract.Burn(amount)
Burn from a specified wallet
- Javascript
- React
- Python
- Go
// Address of the wallet sending the tokens
const holderAddress = "{{wallet_address}}";
// The amount of this token you want to burn
const amount = 1.2;
await contract.burnFrom(holderAddress, amount);
React SDK support for burnFrom is coming soon.
Want this feature sooner? Let us know in Discord!
holder = "{{wallet_address}}"
amount = 0.1
contract.burn_from(holder, amount)
holder := "0x..."
amount := 1
tx, err := contract.BurnFrom(holder, amount)