Token
Learn how to interact with your Token contract in the SDK.
Create a Token Contract
- React
- Javascript
- Python
- Go
- Unity
const sdk = useSDK();
const contractAddress = await sdk.deployer.deployToken({
name: "My Token",
primary_sale_recipient: "your-address",
});
const contractAddress = await sdk.deployer.deployToken({
name: "My Token",
primary_sale_recipient: "your-address",
});
This feature is missing a code snippet or might not be supported yet.
Check the Python SDK Reference for more information.
Reach out on Discord for further assistance!
This feature is missing a code snippet or might not be supported yet.
Check the Go SDK Reference for more information.
Reach out on Discord for further assistance!
await sdk
.deployer
.DeployToken(new TokenContractDeployMetadata()
{ name = "My Collection", primary_sale_recipient = "0x..." });
Getting the contract in your application
To start using your Token contract inside your application, you need to use its contract address. You can get the contract address from the dashboard.
- React
- Javascript
- Python
- Go
- Unity
This feature is missing a code snippet or might not be supported yet.
Check the React SDK Reference for more information.
Reach out on Discord for further assistance!
import { ThirdwebSDK } from "@thirdweb-dev/sdk";
const sdk = new ThirdwebSDK("{{chainName}}");
const contract = await sdk.getContract("{{contract_address}}", "token");
from thirdweb import ThirdwebSDK
# You can customize this to a supported network or your own RPC URL
network = "mumbai"
# Now we can create a new instance of the SDK
sdk = ThirdwebSDK(network)
# If you want to send transactions, you can instantiate the SDK with a private key instead:
# sdk = ThirdwebSDK.from_private_key(PRIVATE_KEY, network)
contract = sdk.get_token("{{contract_address}}")
import (
"github.com/thirdweb-dev/go-sdk/v2/thirdweb"
)
privateKey = "..."
sdk, err := thirdweb.NewThirdwebSDK("mumbai", &thirdweb.SDKOptions{
PrivateKey: privateKey,
})
contract, err := sdk.GetToken("{{contract_address}}")
Contract contract = sdk.GetContract("{{contract_address}}");
Minting Tokens
Mint tokens to a specified wallet
- React
- Javascript
- Python
- Go
- Unity
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);
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);
contract.mint_to("{{wallet_address}}", 1)
tx, err := contract.MintTo(context.Background(), "{{wallet_address}}", 1)
var toAddress = "{{wallet_address}}"; // Address of the Wallet you want to mint the tokens to
var amount = "1.5"; // The amount of this token you want to mint
await contract.ERC20.MintTo(toAddress, amount);
Mint tokens to many wallets in one transaction (batch)
- React
- Javascript
- Python
- Go
- Unity
// 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);
// 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);
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(context.Background(), args)
This feature is missing a code snippet or might not be supported yet.
Check the Unity SDK Reference for more information.
Reach out on Discord for further assistance!
Token Metadata
Get the metadata about the token itself, such as the name, symbol, and decimals.
- React
- Javascript
- Python
- Go
- Unity
const token = await contract.get();
const token = await contract.get();
token = contract.get()
print(token)
currency, err := contract.Get()
symbol := currency.Symbol
var token = await contract.ERC20.Get();
You can get the total supply of the token too.
- React
- Javascript
- Python
- Go
- Unity
const balance = await contract.totalSupply();
const balance = await contract.totalSupply();
This feature is missing a code snippet or might not be supported yet.
Check the Python SDK Reference for more information.
Reach out on Discord for further assistance!
This feature is missing a code snippet or might not be supported yet.
Check the Go SDK Reference for more information.
Reach out on Discord for further assistance!
var balance = await contract.ERC20.TotalSupply();
Token Balance
Balance of the connected wallet
- React
- Javascript
- Python
- Go
- Unity
const balance = await contract.balance();
const balance = await contract.balance();
balance = contract.balance()
print(balance)
balance, err := contract.Balance()
balanceValue := balance.DisplayValue
var balance = await contract.ERC20.Balance();
Balance of a specified wallet
- React
- Javascript
- Python
- Go
- Unity
// Address of the wallet to check token balance
const walletAddress = "{{wallet_address}}";
const balance = await contract.balanceOf(walletAddress);
// Address of the wallet to check token balance
const walletAddress = "{{wallet_address}}";
const balance = await contract.balanceOf(walletAddress);
address = "{{wallet_address}}"
balance = contract.balance_of(address)
print(balance)
address := "{{wallet_address}}"
balance, err := contract.BalanceOf()
balanceValue := balance.DisplayValue
// Address of the Wallet to check token balance
var walletAddress = "{{wallet_address}}";
var balance = await contract.ERC20.BalanceOf(walletAddress);
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 number of tokens that another wallet can spend on behalf of the connected wallet.
- React
- Javascript
- Python
- Go
- Unity
// Address of the wallet to check token allowance
const spenderAddress = "0x...";
const allowance = await contract.allowance(spenderAddress);
// Address of the wallet to check token allowance
const spenderAddress = "0x...";
const allowance = await contract.allowance(spenderAddress);
spender = "{{wallet_address}}"
allowance = contract.allowance(spender)
spender := "0x..."
allowance, err := contract.Allowance(spender)
allowanceValue := allowance.DisplayValue
// Address of the Wallet to check token allowance
var spenderAddress = "0x...";
var allowance = await contract.ERC20.Allowance(spenderAddress);
Get allowance for a specified wallet
Get the number of tokens that another wallet can spend on behalf of the specified wallet.
- React
- Javascript
- Python
- Go
- Unity
// 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.allowanceOf(owner, spender);
// 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.allowanceOf(owner, spender);
# 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
// Address of the Wallet who owns the funds
var owner = "{{wallet_address}}";
// Address of the Wallet to check token allowance
var spender = "0x...";
var allowance = await contract.ERC20.AllowanceOf(owner, spender);
Set Allowance
Specify how many tokens another wallet is allowed to spend on behalf of the connected wallet.
- React
- Javascript
- Python
- Go
- Unity
// Address of the wallet to allow transfers from
const spenderAddress = "0x...";
// The number of tokens to give as allowance
const amount = 100
await contract.setAllowance(spenderAddress, amount);
// Address of the wallet to allow transfers from
const spenderAddress = "0x...";
// The number of tokens to give as allowance
const amount = 100
await contract.setAllowance(spenderAddress, amount);
spender = "0x..."
amount = 100
contract.set_allowance(spender, amount)
spender := "0x..."
amount := 1
tx, err := contract.SetAllowance(context.Background(), spender, amount)
// Address of the Wallet to allow transfers from
var spenderAddress = "0x...";
// The number of tokens to give as allowance
var amount = "100";
await contract.ERC20.SetAllowance(spenderAddress, 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
- React
- Javascript
- Python
- Go
- Unity
// 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.transfer(toAddress, amount);
// 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.transfer(toAddress, amount);
# 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(context.Background(), to, amount)
// Address of the Wallet you want to send the tokens to
var toAddress = "0x...";
// The amount of tokens you want to send
var amount = "0.1";
await contract.ERC20.Transfer(toAddress, amount);
Transfer from the connected wallet in batch
- React
- Javascript
- Python
- Go
- Unity
// 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.transferBatch(data);
// 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.transferBatch(data);
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(context.Background(), args)
This feature is missing a code snippet or might not be supported yet.
Check the Unity SDK Reference for more information.
Reach out on Discord for further assistance!
Transfer from a specified wallet
- React
- Javascript
- Python
- Go
- Unity
// 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.transferFrom(fromAddress, toAddress, amount);
// 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.transferFrom(fromAddress, toAddress, amount);
# 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(context.Background(), from, to, amount)
This feature is missing a code snippet or might not be supported yet.
Check the Unity SDK Reference for more information.
Reach out on Discord for further assistance!
Burning Tokens
Burning tokens takes a specified amount of tokens out of the circulating supply.
Burn from the connected wallet
- React
- Javascript
- Python
- Go
- Unity
// The amount of this token you want to burn
const amount = 1.2;
await contract.burnTokens(amount);
// The amount of this token you want to burn
const amount = 1.2;
await contract.burnTokens(amount);
amount = 0.1
contract.burn(amount)
amount := 1
tx, err := contract.Burn(context.Background(), amount)
// The amount of this token you want to burn
var amount = "1.2";
await contract.ERC20.Burn(amount);
Burn from a specified wallet
- React
- Javascript
- Python
- Go
- Unity
// 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);
// 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);
holder = "{{wallet_address}}"
amount = 0.1
contract.burn_from(holder, amount)
holder := "0x..."
amount := 1
tx, err := contract.BurnFrom(context.Background(), holder, amount)
This feature is missing a code snippet or might not be supported yet.
Check the Unity SDK Reference for more information.
Reach out on Discord for further assistance!