Transaction fees

How to estimate fees to submit a transaction on a blockchain network.

Introduction

Public distributed ledger technologies such as Ethereum and Bitcoin use a variable fee model that adjusts transaction fees based on the current traffic and amount of processing that your transaction will require.

Blockchain network transaction fees only apply when writing data to the blockchain by sending transactions. Read operations, such as getting the balance of an account or checking the state of a smart contract do not require fees.

This article will describe the fee estimation process for Ethereum-based blockchain networks, Bitcoin, Substrate and XRP Ledger.

Fee estimation

Overledger uses fee estimation tools that are native to the technologies we support.

Fee estimation happens during the transaction prepare stage. Overledger gathers data about the current state of the blockchain network straight from the nodes and returns an estimation of the cost depending on the payload the user sends with their transaction.

Each technology we support has a slightly different structure. If fees are an important concern even while interacting with the test networks, we strongly advise familiarising yourself with the various models employed by the technology you would like to use.

Ethereum fees

Ethereum employs a gas fee model, where every computation the node executes to apply your transaction, is associated with a certain amount of gas units. This allows the decoupling between the computational cost of transactions and the monetary value of Ether.

When preparing transactions for Ethereum-based technologies, Overledger will return three fields relating to fees in the nativeDatasection of the response body.


  • gas- the number of gas units required for your transaction. Overledger gets this value from the node, based on the type of transaction we are sending. In the case of smart contract transactions, the node will simulate the transaction and return this value based on the simulation.

  • maxPriorityFeePerGas- a "tip" that we need to offer the validator nodes to include the transaction on the blockchain. Without providing a tip, blockchain validator node operators have no incentive to include the transaction in the next block, as they would get no reward for the computation done. Overledger also gets this value from the node, using the Ethereum node's built-in API for fee estimation. The call we submit to the Ethereum node is configured to return the lowest value the node can estimate to get the transaction applied. On the testnets, this value will be much lower than in production.

  • maxFeePerGas- the maximum amount of Ether per gas unit you are willing to spend on the transaction. It is calculated by summing up the baseFeePerGas(which also comes from the network and fluctuates based on traffic) and the maxPriorityFeePerGas.

Overledger makes it simple for developers to view the total amount of Ether a transaction would cost by aggregating these three values into a single Ether amount. This result is returned together with the transaction preparation response in the dltFees section:

"dltFee": {
    "amount": "0.002163200025006592",
    "unit": "ETH"
},

For more information on Ethereum fees, we recommend viewing this article from the Ethereum Foundation: https://ethereum.org/en/developers/docs/gas/

Bitcoin fees

Bitcoin has a much simpler fee model. There is a fee rate that is determined by the network depending on traffic at that time. This fee rate is then multiplied by the transaction size in bytes. Overledger returns the details of this calculation in the nativeData section of the transaction preparation response. Moreover, Overledger provides developers with a simple estimation in BTC in the dltFee section of the response.

Substrate (Polkadot) fees

In Substrate, we have the concept of fee and weight. It is similar to Bitcoin in that the fee is retrieved from the network and it changes depending on traffic. The weight is proportional to the execution time (input, output, and computation) that a transaction consumes. Overledger provides an estimation in DOT (or WND for the Polkadot Westend Testnet) in the dltFeesection of the response.

XRP Ledger fees

XRP Ledger also has a simple fee structure, given by a base network fee and adjusted to the various XRP Ledger transaction types. Overledger returns this estimation in the dltFee section of the response.