Gas consumption in OKP4 blockchain

Understanding Gas Fees in Blockchain


Gas fee is a term used in blockchain technology that refers to the cost associated with executing a transaction or a smart contract on a network. Users pay the gas fee to compensate validators who process and verify these transactions on the network. This fee is usually denominated in the network’s native cryptocurrency and is determined by the complexity of the transaction or smart contract code and the amount of computational resources needed to execute it.

Gas fees serve two primary purposes. First, they are used to prioritize transactions on the network, with higher gas fees resulting in faster transaction confirmations. This prioritization ensures that more important transactions are processed first. Second, gas fees protect against spamming and malicious attacks on the network, as each transaction requires a specific amount of gas fee to be processed. Therefore, the higher the gas fee, the more expensive it is to launch an attack on the network, making it more secure.

Very early, spamming problem was detected on the cosmos ecosystem : Learn more about it


Understanding the Difference Between GasWanted and GasUsed in Blockchain Transactions

The gas amount set by a user as “GasWanted” for a transaction often differs from the actual gas amount used, known as “GasUsed”. This disparity arises because estimating the gas required for a particular transaction can be challenging and depends on several factors, such as the complexity of the transaction and the current network congestion.


To ensure that our transactions are executed successfully, we, as users, often tend to overreact by paying more gas fees than necessary. This is because we don’t want to face the frustration of paying gas fees and waiting for a transaction that ultimately fails to be executed.

By examining gas consumption in the OKP4 blockchain, we can investigate potential solutions for executing transactions with the ideal gas fees. But before starting, let’s connect our KEPLR wallet to the OKP4 blockchain. Don’t have a KEPLR wallet : follow our step-by-step Guide!

Are you ready?

1 – Connect to Aviaone Blockchain Service and click on the link as following:

AVIAONE blockchain SERVICE

2 – You will be redirected to OKP4 Explorer and click on “Connect Wallet

add OKP4 Network to KEPLR

3 – Click “Next

add OKP4 Network to KEPLR

4- Click “Approve” to add the OKP4 Network to your wallet

add OKP4 Network to KEPLR

5 – Add a Account Name and click “Next

add OKP4 Network to KEPLR

6 – Click “Save” and your wallet is all set! Congratulations

add OKP4 Network to KEPLR

KEPLR wallet KNOW token

Now, Let’s talk about …. Gas!

According this page Gas fee can be calculated as following :

[Gas fee] = [Gas units] * [Gas price]

The term “gas units” refers to the amount of computational effort necessary to perform certain operations on the network, while “gas price” is a price that varies depending on the level of network congestion. This price is determined by the network and can automatically fluctuate based on the current network congestion.

We will focus on the gas units here in this document.


This article covers Phase 4 of the Testnet called “Nemeton“, where gas-prices are set to 0, resulting in no gas fees being charged when executing a transaction. However, in the mainnet, it is recommended that validators increase the minimum fee (minimum-gas-prices parameter) to prevent spam, which means that each transaction will incur a real cost in uKNOW.

minimum-gas-prices from validator OKP4

The minimum fees accepted in the network are determined by validators, and each validator can specify a different minimum value for their fees. Therefore, the same transaction can have varying gas fees.

Gas Adjustment

Let’s experiment with adjusting the gas units with the Gas Adjustment parameter and see how it affects the transaction. To begin, we can try sending some tokens to another wallet and observe the outcome.


The –gas-adjustment parameter is an optional tool that allows users to scale up the gas amount in order to avoid underestimation. By specifying a gas adjustment value of 1.15, for instance, a user can use 1.15 times (or 15%) the estimated gas for a transaction.

okp4d tx bank send okp417x0ewz3gwwk52eeryhg89q6g0zknpwlm8pvw7p okp41qkunw6ey2j5ltm8s3nyffnz3tu6pygmglyy9hl 1uknow --chain-id=okp4-nemeton-1 --gas-adjustment=1.15 --fees=0.000001uknow


Request for Sending token OKP4 bash command

Transaction executed! Check it out

Wallet KEPLR first transaction OKP4

set 200000 manually gas fee

OKP4 Scan

set 200000 gas fee

When we look at the transaction details, we can see that the GasWanted was set to 200,000, but the actual GasUsed was only 77,128. This means that 122,872 gas was sent unnecessarily. To avoid such gas losses, we can explore ways to optimize our gas usage in the future.

If we don’t define the gas adjustment and only specify “gas auto,” the gas will be automatically estimated by the network.


gas auto tx OKP4 Cosmos

fail tx

As we can see, GasWanted (60686) is lower than GasUsed (61155) so transaction failed.


error gasWanted to low

Let’s try setting a gas adjustment of 1.15 and use gas auto to see the impact on the gas consumption.


gas adjustment 1.15 on OKP4

Success Transaction : Check it out !

success tx on OKP4

The result of the experiment shows that the GasUsed and GasWanted are very close to each other, which is the intended outcome. However, as a user, you might wonder how to utilize the gas adjustment in your own transaction with KEPLR.

Keplr offer this possibility as followed :


gas adjustment into KEPLR

Let’s increase the gas adjustment to 1.5 to see if it actually works as expected:

gas adjustment 1.5

success tx

As expected, the GasWanted has increased. Check it out !

It appears that determining the appropriate gas adjustment value is crucial for achieving the optimal gas fee amount, which is closest to the GasUsed. However, what if users were able to input a significant amount of gas fees and receive a refund for the unused gas during the transaction?

[RefundGas] = [GasWanted] – [GasUsed]

Implemented on Ethermint in 2021:

ethermint gas refund function

But there are still conversations about it in 2022.

don't refund all the unused gas

Objectarium smart contract provided by OKP4 team

The functionality of the okp4-objectarium smart contract involves the storage of objects in any Cosmos blockchain using the CosmWasm framework. This contract facilitates the storage, pinning, and unpinning of objects for a specified sender address. It also allows for object removal or forgetting if they are no longer pinned.

Let’s try to instantiate with gas auto parameter :

tx instantiate Objectarium smart contract

As observed, the use of gas auto results in a GasWanted value that is relatively high compared to a regular transaction.

Let’s try to high up the gas manually to 100000 :

gas fee set to 100000

Transaction failed : check it out!

tx failed

Let’s try to high up manually to 120000

gas fees set to 120000

fail tx

Let’s high up to 200000 :

gas fees to 200000

success tx

It appears that an average gas unit of 200,000 is suitable for the instantiate action, while a simpler transaction requires only around 65,000 gas units. This suggests that each specific action requires a different average gas amount, which makes sense as more complex requests would require more computing power compared to simpler ones.

In summary, there are three possible solutions to accurately determine the right amount of gas for a transaction:

  1. Conduct a large quantity of the same action and calculate the average of GasUsed to determine the right Gas adjustment to enter on the request. The formula for this solution could be:

Gas adjustment = (((Sum(GasUsed n….n + 1))/n) – GasWanted)*100/GasWanted)+1

  1. Calculate the RefundGas. In this case, as long as the gasWanted is higher than the GasUsed, the transaction will be executed and the extra gas will be refunded to the sender of the request.
  2. Use the Aviaone API service and execute a simulation of a transaction similar to the one you want to execute to see the estimated fees.

Aviaone Api service