EVM - Create a Fungible Token
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.
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": "track visual goat celery cabbage rule toss assist hawk wheat shrug music unit undo eternal dutch short elder question penalty rain tortoise garden recipe"
}
Step_2: Generate an ETH Address from XPUB and index
Request example:
- Returns an Externally Owned Address (EOA)
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 a PrivateKey
curl --location 'https://api.tatum.io/v3/ethereum/wallet/priv' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {YOUR_API_KEY}' \
--data '{
"mnemonic": "track visual goat celery cabbage rule toss assist hawk wheat shrug music unit undo eternal dutch short elder question penalty rain tortoise garden recipe",
"index":1 //We use the same index as in step_2
}'
//response:
{
"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
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/v3/ethereum/account/balance/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 at the following link.
Request Example:
- Request Body Schema:
EstimateFee
with type:DEPLOY_ERC20
- Returns the estimated
GasPrice
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",
"sender": "0x0d79b1ce812b09b38de78bd6e96f494db8344561",
}'
//Response:
{
"gasLimit": 2000000,
"gasPrice": 11.489560031
}
Step_7: Deploy a Smart Contract Fungible Token (ERC-20 or compatible)
Request example:
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":"0x13d9affe6dc6ed1882d5b9af836921fa8183763a",
"fee": {
"gasLimit": "2000000",
"gasPrice": "12"
},
"fromPrivateKey":"####"
}'
//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
β.
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":"####"
}'
//response:
{
"txId": "0x86f912607ce66da4f1f8ff75fd639cc69ecc8bf64763225bf5c15fc16bea3f5c"
}
Step_10: Burn tokens (optional)
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":"####"
}'
//response:
{
"txId": "0xf7d5127c88a388f0f9c021737a8a24d7084b7f444b7ba8cb6a34d41953160c4d"
}
Updated 4 months ago