About Transaction Fee of Cosmos Hub

Node A-Team
Node A-Team
Published in
5 min readMay 24, 2019

--

It’s only been a little more than 2 months since the launch of Cosmos Hub, and many users are confused about out transaction fee works on the Hub. This post is for users to understand the basic fundamentals of transaction fee so that they can send transactions in a safer, and more efficient manner.

Transactions that use excessive fee

https://github.com/b-harvest/rescue-fatfinger

The user above used 29,959 Atoms as transaction fee! Based on current price of the Atom (2019. May 24th), 29,595 Atoms is approximately $134k!

The user above is currently receiving donations from validators who benefited from this excessive transaction fee. Node A-Team has also joined this donation to return the Atoms which was sent to our node due to the transaction above.

Transaction Fee System

Transaction fee system of Cosmos Hub is actually quite simple. Anyone who has been interested about blockchain technology probably knows about Gas on Ethereum. Cosmos Hub, like Ethereum, has a similar gas system. On a blockchain, gas is used to read and write state, and perform logic, and users will use maximum amount of gas when sending transaction. Gas, therefore, indicates how much burden this transaction has given the blockchain. The transaction fee will pay for the gas required for the transaction. Also, there is a gas price which shows how much 1 gas costs. Total fee will equal [Gas * Gas Price]. The minimum gas price is set by each validator of the network. Validators will evaluate their profit, stability of the blockchain and relevant factors to set the lowest, but acceptable gas price, and only the transactions with gas price beyond the set value will be included in the block.

*The actual gas price does not exist within the transaction, but validators will calculate [fee / gas] when verifying the transaction. Transactions with gas price higher than the value set by the validators will be accepted into the mempool, and will include them in the blocks created afterwards.

Gas is a crucial part in deciding transaction fee. If there is not enough gas, the transaction will fail, and the used gas will not be refunded to the user. The user, thus, will only waste fee in this case. If the user uses too much gas, the transaction will be successful, but the remaining gas will not be refunded and therefore, will be wasted. The required gas will change based on the logic performed in each transaction, which makes it very difficult to calculate beforehand. The wallets, which we use, will simulate a transaction or use statistical data per transaction type to set a fixed set of gas value.

We’ve now looked into the fundamentals of gas system, so let’s look into how to apply them to the wallets.

How to use Gaiacli

Let’s look into an example of sending a token on Gaiacli.

First, we have to set the config of Gaiacli.

gaiacli config chain-id cosmoshub-2
gaiacli config node {your_rpc_node}

We will use this simple command to send a transaction.

gaiacli tx send cosmos15vztx5tw4np99favm9gat9tj0hd9x26ucrf8vl 1uatom — from test — fees 1uatom

Response:

Height: 372015

TxHash: 8C874A6FFF8B2F76CFCD1CCF3471FF2C34EDC2E7786B9DDA3D1C963C16BD4E0A

Raw Log: [{“msg_index”:”0",”success”:true,”log”:””}]

Logs: [{“msg_index”:0,”success”:true,”log”:””}]

GasWanted: 200000

GasUsed: 27561

Tags:
- action = send
- sender = cosmos15vztx5tw4np99favm9gat9tj0hd9x26ucrf8vl
- recipient = cosmos15vztx5tw4np99favm9gat9tj0hd9x26ucrf8vl

When we look at the result of the transaction, we can see that Gas is set at 200,000. But the actual gas used for this transaction is only 27,561. Currently, validators are accepting low fee so this will not be a problem, but in the future, if too much fee is used, there will be no refund and users will waste the remaining gas. So, we have to be more specific with setting gas value.

gaiacli tx send cosmos15vztx5tw4np99favm9gat9tj0hd9x26ucrf8vl 1uatom — from test — gas=”auto” — gas-adjustment=1.15 — gas-prices=0.000001uatom

Response:

Height: 372095

TxHash: 31EE7C77D6D1BC31E892B763F7BCFC9237DB6B95C14B15252B4E7319A8DE4E94

Raw Log: [{“msg_index”:”0",”success”:true,”log”:””}]

Logs: [{“msg_index”:0,”success”:true,”log”:””}]

GasWanted: 30265

GasUsed: 27585

Tags:
- action = send
- sender = cosmos15vztx5tw4np99favm9gat9tj0hd9x26ucrf8vl
- recipient = cosmos15vztx5tw4np99favm9gat9tj0hd9x26ucrf8vl

We can use gas and gas-adjustment flags to set gas through a simulation. The gas is set as [GasUsed * gas_adjustment]. The simulation result might be slightly different from when the actual transaction is accepted and added to the block, thus we can add 10~25% to gas_adjustment value to optimize the gas value.

Lunie

Purpose of this post is not to provide a guide to Lunie. But if you are new to Lunie and need a guide, please refer to our Lunie guides below:

After testing multiple transactions on Lunie, we could assume that Lunie simulates a transaction first and then sets gas price of 0.03 uatom to calculate transaction fee. It might seem inconvenient that we cannot set our own gas price, but it seems efficient enough since gas price on Lunie is already low enough.

Lunagram

https://play.google.com/store/apps/details?id=com.lunamint.lunagram

Lunagram is a very efficient Cosmos wallet which directly connects to your Telegram account. Currently, we cannot set gas value at the transaction fee selection stage, and it seems like gas is fixed at 200,000. Currently we can only change transaction fee, but when Cosmos Hub grows larger and meaningful amount of transaction fee is used and more transactions are added to the blocks, 200,000 gas will be too large for each transaction.

Cosmostation Wallet

Like Lunagram, which is introduced above, Cosmostation wallet also looks like they’re using 200,000 gas, and only allowing adjustment of transaction fee.

Conclusion

We are only at the beginning of the Cosmos Ecosystem, and some of the most used wallets may have some inconvenience in setting specific fees. Currently gas fees are small and there are not a lot of transactions, but we believe this part will also be improved in the future. Lastly, we thank all the wallet developers for their effort to improve the overall ecosystem of Cosmos.

Node A-Team (Moniker: ATEAM) is a Cosmos-SDK and Tendermint-based Blockchain Validator, which currently participates in Cosmos, IRISnet and Terra. Based on the knowledge and experience gained from various testnets and mainnet, Node A-Team contributes to Cosmos Ecosystem and operates highly secure nodes.

> ATEAM History
— Cosmos: “Game of Stakes” — Never Jailed
— IRISnet: “FUXI Betanet” — Reward Winner
— Terra-project: “Genesis Drill” — Top Tier

[ATEAM Validator Address: cosmosvaloper14l0fp639yudfl46zauvv8rkzjgd4u0zk2aseys]

Webpage: https://nodeateam.com/

Twitter: https://twitter.com/Node_Ateam

E-mail: contact@nodeateam.com

--

--

Node A-Team
Node A-Team

Cosmos Validator based in South Korea. “Never Jailed” winner of Game of Stakes. https://nodeateam.com