EVM - Create a Fungible Token
Create an ERC-20 fungible token by deploying a token contract with the Tatum REST API, then get its contract address and mint or burn tokens.
Creating a fungible token (ERC-20, BEP-20, or compatible) involves defining the parameters of the token, such as its name, symbol, and total supply, within a Smart Contract on the Ethereum chain or other EVM-compatible networks. To create a token on Solana, see Create an SPL token on Solana. To deploy an ERC-20 token from a browser dApp and sign with MetaMask, see Create an ERC-20 token with MetaMask.
The following steps and examples are based on Ethereum Sepolia (testnet).
Steps
Step_1: Generate an ETH wallet
Example request:
- Returns Mnemonic and XPUB
curl --location 'https://api.tatum.io/v3/ethereum/wallet' \
--header 'x-api-key: {YOUR_API_KEY}'Response:
{
"xpub": "xpub6EQoqwU4mibGqyz7EurdQifKhD5KNJRqSZbtechfNnHwiGFYpFd8i6nBZRmeFTa66jXsUoXafHHcx3XAqsbjhcpGf9X8S3m95Av8oAPXAg6",
"mnemonic": "{MNEMONIC}"
}Step_2: Generate an ETH Address from XPUB and index
Request example:
- Returns an Externally Owned Address (EOA) for index
1
curl --location 'https://api.tatum.io/v3/ethereum/address/xpub6EQoqwU4mibGqyz7EurdQifKhD5KNJRqSZbtechfNnHwiGFYpFd8i6nBZRmeFTa66jXsUoXafHHcx3XAqsbjhcpGf9X8S3m95Av8oAPXAg6/1' \
--header 'x-api-key: {YOUR_API_KEY}'Response:
{
"address": "0x0d79b1ce812b09b38de78bd6e96f494db8344561"
}Step_3: Generate a PrivateKey based on mnemonic and index
Request example:
- Returns the PrivateKey of the address from Step_2. Use the same
indexas in Step_2 (1).
curl --location 'https://api.tatum.io/v3/ethereum/wallet/priv' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {YOUR_API_KEY}' \
--data '{
"mnemonic": "{MNEMONIC}",
"index": 1
}'Response:
{
"key": "{PRIVATE_KEY}"
}Step_4: Add funds to the EOA that will deploy the Smart Contract Fungible Token (ERC-20)
-
Following the address from the example,
{ "address": "0x0d79b1ce812b09b38de78bd6e96f494db8344561" } - For testnet, you can use a faucet.
Step_5: Check the Native asset balance of an address
- v4 Data API endpoint: Ethereum, Celo, Polygon and other chains
You need to make sure the Sender's blockchain address has enough Native assets to cover the gas fees of the transfer. See the Fee Estimate step below.
Example request:
- Returns address balance in Native assets
curl --location 'https://api.tatum.io/v4/data/blockchains/balance?chain=ethereum-sepolia&address=0x0d79b1ce812b09b38de78bd6e96f494db8344561' \
--header 'x-api-key: {YOUR_API_KEY}'Response:
{
"balance": "1.019834873884184342"
}Step_6: Estimate a Smart Contract Deployment fees
Deploying (or creating) a Smart Contract has a cost associated with gas fees to be paid with Native assets. Additional information on Fee Estimate is available in How EVM fee estimates work.
Request Example:
- Request Body Schema:
EstimateFeewith type:DEPLOY_ERC20 - Returns the estimated
gasPrice(in Gwei) andgasLimit
curl --location 'https://api.tatum.io/v3/blockchain/estimate' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {YOUR_API_KEY}' \
--data '{
"chain": "ETH",
"type": "DEPLOY_ERC20"
}'Response:
{
"gasLimit": 2000000,
"gasPrice": 11.489560031
}Step_7: Deploy a Smart Contract Fungible Token (ERC-20 or compatible)
Request example:
addressreceives the initialsupply. This example uses the address from Step_2.fromPrivateKeyis the private key from Step_3. Its address pays the deployment fee, so it needs the funds from Step_4.fee.gasPriceis in Gwei: the estimate from Step_6, rounded up.
curl --location 'https://api.tatum.io/v3/blockchain/token/deploy' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {YOUR_API_KEY}' \
--data '{
"chain": "ETH",
"symbol": "TTOKEN",
"name": "Tatum_Token",
"totalCap": "200000000",
"supply": "100000",
"digits": 18,
"address": "0x0d79b1ce812b09b38de78bd6e96f494db8344561",
"fee": {
"gasLimit": "2000000",
"gasPrice": "12"
},
"fromPrivateKey": "{PRIVATE_KEY}"
}'Response:
{
"txId": "0x5ac15c341d426d1e1ec11d7a99935c644ebdf595af26ef3c805e3912a49ef114"
}Step_8: Get the ContractAddress from a transaction hash
Request example:
curl --location 'https://api.tatum.io/v3/blockchain/sc/address/ETH/0x5ac15c341d426d1e1ec11d7a99935c644ebdf595af26ef3c805e3912a49ef114' \
--header 'x-api-key: {YOUR_API_KEY}'Response:
{
"contractAddress": "0xCf15c60f66e49d3C41a98717eb0f40AcD764DD57"
}Step_9: Mint additional ERC-20 tokens (optional)
- v3 REST API endpoint
- We can do this since in Step_7, the “
supply” was less than the total specified in the parameter “totalCap”. fromPrivateKeyis the private key of the address that deployed the contract (Step_3).tois the address that receives the new tokens.
Request example:
curl --location 'https://api.tatum.io/v3/blockchain/token/mint' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {YOUR_API_KEY}' \
--data '{
"chain": "ETH",
"amount": "100000",
"contractAddress": "0xCf15c60f66e49d3C41a98717eb0f40AcD764DD57",
"to": "0x7a8c2f6f3bd2dc45812e5daae0373eaef2e2dddd",
"fromPrivateKey": "{PRIVATE_KEY}"
}'Response:
{
"txId": "0x86f912607ce66da4f1f8ff75fd639cc69ecc8bf64763225bf5c15fc16bea3f5c"
}Step_10: Burn tokens (optional)
- v3 REST API endpoint
- Tokens are burned from the address that signs the transaction: here the address from Step_2, which received the initial supply.
Request example:
curl --location 'https://api.tatum.io/v3/blockchain/token/burn' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {YOUR_API_KEY}' \
--data '{
"chain": "ETH",
"amount": "50000",
"contractAddress": "0xCf15c60f66e49d3C41a98717eb0f40AcD764DD57",
"fromPrivateKey": "{PRIVATE_KEY}"
}'Response:
{
"txId": "0xf7d5127c88a388f0f9c021737a8a24d7084b7f444b7ba8cb6a34d41953160c4d"
}Updated 6 days ago