EVM - Fee Estimate, GasPrice and Insufficient funds Error

When building a transaction over EVM chains (like Ethereum), common pitfalls making the broadcast transaction attempt fail are:

  • Using manual fee, where gasPrice is in Wei instead of Gwei.
  • The sender's address holds no balance or insufficient balance, be it in token or in native assets to pay the miner's for the gas fees.
  • The PrivateKey does not match with the expected sender's address

When this happens, you will likely get an error looking as follows:

//variant_1:
{
  statusCode: 403,
  errorCode: 'eth.tx.preparation',
  message: 'Transaction preparation failure.',
  cause: 'Insufficient funds send transaction from account ####### -> available balance is 1800000000000000, required balance is 7.233615778886385e+23'
}
//variant_2:
{
  "statusCode":403,
  "errorCode":"bsc.tx.preparation",
  "message":"Transaction preparation failure.",
  "cause":"Insufficient funds to send transaction from account ######, Error: Returned error: gas required exceeds allowance (11500)",
  "dashboardLog":"https://dashboard.tatum.io/logs?id=######"
}

Fee Estimate

Tatum Fee estimates endpoints return values in Wei.

Example ETH Fee Estimate:

curl --location 'https://api.tatum.io/v3/ethereum/gas' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {API_KEY}' \
--data '{
    "from": "0xBF5c7e33a316cf7D86eBF4014bCf798c6962####",
    "to": "0xce864aaec47f07ee8ba7e60a37ff141298f7####",
    "amount": "0.018"
}'
//response:
{
    "gasLimit": "21000",
    "gasPrice": "43698096524", //The unit hereis in Wei!
    "estimations": {
        "safe": "43698096524",
        "standard": "43698096524",
        "fast": "43698096524",
        "baseFee": "43914769922"
    }
}

Sending Ethereum with manual fees

When building an Ethereum transaction, if you want to input the transaction fee manually, make sure the gasPrice is in Gwei.

📘

1 Gwei (Giga-wei) is equal to 1,000,000,000 Wei. Therefore, to convert Wei to Gwei, you have to divide the amount in Wei by 1,000,000,000. Alternatively, you may use an online conversion such as eth-converter.com

Example ETH transaction with Manual Fees:

curl --location 'https://api.tatum.io/v3/ethereum/transaction' \
--header 'Content-Type: application/json' \
--header 'x-api-key: ##Mainnet_API_KEY' \
--data '{
    "to": "0xd2c4b6434410e4af062ee3c280327c8ece11####",
    "currency": "ETH",
    "amount": "0.0017",
    "fromPrivateKey": "****",
    "fee": {
        "gasLimit": "21000",
        "gasPrice": "44" //unit in Gwei! -> Estimate returned "fast": "43698096524",
    }
}'