About Token Decimals (ERC-20 or compatible)
Decimals refer to how divisible a token can be, ranging from 0 (not divisible) to 18 (highly divisible). In some cases, the token contract may support even more or fewer decimals, depending on its design.
You may determine a token's decimals using the RPC method eth_call
on the token's contract address or by consulting a blockchain explorer. If the information isn't readily available, consider checking the token's documentation via a web search.
EVM: Ethereum ERC-20 or compatible
To confirm the decimals of an ERC-20 (or compatible) token, you can either:
- Query the token's contract using the RPC eth_call method.
- Look up the token's contract address on a blockchain explorer.
Example: Find Decimals via RPC eth_call
- Example Token: Tether USDT
- Contract Address: 0xdac17f958d2ee523a2206206994597c13d831ec7
- Decimals Supported: Six (6)
curl --location 'https://ethereum-mainnet.gateway.tatum.io' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {YOUR_API_KEY}' \
--data '{
"jsonrpc": "2.0",
"id": 1,
"method": "eth_call",
"params": [
{
"to": "0xdac17f958d2ee523a2206206994597c13d831ec7", // Replace with the token's contract address
"data": "0x313ce567" // Keccak-256 hash of "decimals()"
},
"latest"
]
}'
//Response:
{
"id": 1,
"jsonrpc": "2.0",
"result": "0x0000000000000000000000000000000000000000000000000000000000000006"
}
The result value (0x06) indicates that the token supports 6 decimals.
Example: Find Decimals via a Blockchain Explorer
Example request to transfer tokens:
curl --location 'https://api.tatum.io/v3/blockchain/token/transaction' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {YOUR_API_KEY}' \
--data '{
"chain": "ETH",
"contractAddress": "0xdac17f958d2ee523a2206206994597c13d831ec7", //The Token Address
"digits": 6, // Amount of supported decimals by the Token contract
"amount": "1.123456", // Decimals amount must be lower or equal to "digits" parameter
"to": "0x5593549ead3b3bd6e4b049ed607ec0f422208298",
"nonce": 13,
"fee": {
"gasLimit": "52036",
"gasPrice": "23"
},
"fromPrivateKey": "SENDER_ADDRESS_PRIVATE_KEY"
}'
import {sendEthOrErc20Transaction} from '@tatumio/tatum';
/**
* Send Ethereum or supported ERC20 transaction to the blockchain.
* @param chain - chain to work with
* @param fromPrivateKey - private key of sender address. Private key, or signature Id must be present.
* @param contractAddress - address of ERC20 token
* @param digits - number of decimal points that ERC20 token has
* @param amount - amount to be sent
* @param to - blockchain address to send ERC20 token to
* @returns transaction id of the transaction in the blockchain
*/
const transaction = await sendEthOrErc20Transaction({
chain: Currency.ETH,
fromPrivateKey: '##_related_pric_address_here_##',
contractAddress: '0xdac17f958d2ee523a2206206994597c13d831ec7', //ERC-20 Smart Contract Address
digits: 6, // The token supports 6 decimals (see Token Contract)
amount: "100000",
to: "##_destination_address_here_##"
});
Tron: TRC-20
To confirm the decimals of a TRC-20 token, check its token address using the Tronscan Explorer.
Example Token: Tether USDT:
- Contract Address: TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t
- Decimals Supported: Six (6)
Example request to transfer tokens:
curl --location 'https://api.tatum.io/v3/tron/trc20/transaction' \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header 'x-api-key: {YOUR_API_KEY}' \
--data '
{
"fromPrivateKey": "SENDER_ADDRESS_PRIVATE_KEY",
"to": "TF48MUvZhSDpLFfC414b94Nj4LwqBFbXom",
"tokenAddress": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t", //TRC-20 Smart Contract Address
"feeLimit": 100,
"amount": "100.123456" // The token supports 6 decimals (see Token Contract)
}'
Updated 21 days ago