Ethereum is an open-source computing platform that includes smart contract functionality. Ethereum uses its token, Ether, to transact accounts and compensate for computations performed. Web3j provides an integration layer to the Ethereum blockchain for Java applications.

To start, anything that is computed within Ethereum and executed is considered a transaction. For example, if a user INSERTS data into an application from the Ethereum blockchain, then functions such as MATCH can locate and render search results. Additional functions include CREATE, such as a contract, and STORE, on the blockchain, which are considered transactions where some amount of computational work is being done to result in an action with the blockchain.
With this in mind, each transaction in the system has a fee associated with it. Meaning, a custom application will be charged a fee in Ether per transaction (transaction fee) that a Miner will collect. However, a few business models include a miner as an employee of the company where miners receive a percentage of the transaction fee earned. This is analogous to commission, for example each transaction a miner validates, 3% of the earnings per transaction go to the miner.
What is a transaction fee?
A transaction fee is the combination of both the Gas price and the Gas cost per transaction. Gas is the name for a special unit used in Ethereum. It measures how much “work” an action or set of actions perform. The reason Gas is important is because it ensures that the network doesn’t become bogged down with performing a lot of intensive work that isn’t valuable to anyone.
So, if Gas is basically a transaction fee, how do you pay it?
When it comes to actually paying for the Gas, the transaction fee is paid out as a certain number of Ether and you are rewarded Ether for creating new blocks as well.
So why don’t transactions have a cost measured in Ether directly instead of Gas?
This is because Ether has a market price that can change rapidly, but the cost of computation does not go up or down, therefore, Ethereum has separated the price of computation from the price of the Ether coin. Although, a miner can heavily influence the price of the Ether coin.
Transactions in Ethereum have a Gas cost, but Gas itself also has a Gas price measured in Ether. Every transaction specifies the Gas price it is willing to pay in Ether for each unit of Gas, hence, this allows the market to decide the relationship between the price of Ether and the cost of computing transactions (measured in Gas). It’s the combination of the two, total Gas used multiplied by Gas price paid, that results in the total fee paid by a transaction. There is a difference between your transaction running out of Gas and your transaction not having a high enough fee. If the Gas price in my transaction is too low, nobody will bother to run my transaction.
What is Gas price and Gas cost?
Think of it like this. Gas price is equivalent to an hourly wage, whereas, Gas cost is equivalent to the actual work performed.
For example, if you hire a painter, then you pay the painter $20 an hour (Gas price) and his fee for painting is $1000 (Gas cost). We, as the developers, set the Gas price. We do not, however, set the Gas cost. In this example, we offered the painter $20 an hour, however he set his fee of $1000 himself. Miners will look at the Gas price being offered per transaction and based on that, they will decide if they want to put work into the transaction. Let’s say we set a very high Gas price, we will end up paying lots of Ether for only a few transactions. But, if we provide a normal Gas price, then we can avoid that issue. Therefore, there is a difference between a transaction running out of Gas (like running out of funds to continue paying the painter) and the transaction not having a high enough fee (not offering enough Gas price, i.e., if we offered the painter $8 an hour instead of $20, he most likely will not bother to work).
Let’s circle back to the basics.
A transaction fee is a combination of Gas price and Gas cost. In this instance, the Gas price would be analogous to offering the painter $20 an hour and Gas cost would be analogous to the painter charging us $1000 as his cost. Now, before the painter starts his work, we will have our budget. Let’s say our budget is $1500 and we do not want the painter to go beyond our budget. The $1500 budget is equivalent to the StartGas. This is how much Gas we will have available for the entire transaction to happen. But, let’s say the painter notices that he also needs to remove wallpaper. Because we did not take that into account, the painter can charge an extra $600 just to remove the wallpaper which will put us well over budget.
Based on this, we have to be extremely strategic with determining how much computational work will be involved in each transaction (keeping each transaction as simple as possible). This is because if I provide an acceptable Gas price and my transaction results in much more computational work that the combined Gas costs go beyond the amount I attached as a fee (StartGas), then that Gas counts as “spent” and we don’t get it back. The miner will stop processing the transaction, revert any changes made, but still include it in the blockchain as a “failed transaction”, collecting the fees for it. This seems harsh, but based on the amount of work that a miner performs, it’s only fair that we pay them for the work they did, even though our badly designed transaction ran out of Gas. The smart way to handle this would be to attach more Ether than necessary to pay for the Gas that our transaction will consume so that the excess amount will be refunded back to us.
Gas is the key mechanism that makes our strategy STRONG in Ethereum and “safe”. This concept makes sure that nothing runs forever and that people will be careful about the code they run. It keeps both miners and user’s safe from bad code!
Again, each transaction has a transaction fee. Within each transaction fee, there is a Gas price and Gas cost (how much the computation costs). Consider Gas to be synonymous with fuel, a transaction must provide enough fuel, or StartGas, to cover its entire use of the computation. All remaining Gas is refunded to the business application. A transaction that runs out of Gas is reverted, but is still included in a block and the fees are paid to the miner.
Gas is the transaction fee for every operation made in Ethereum. Its price is expressed in Ether and is decided by the miners, who can refuse to process a transaction with less than a certain Gas price. This is how the value of Ether as a coin is ultimately determined in the market. To get Gas, we simply add Ether to our account.
Ethereum has implemented a transaction environment on the blockchain called the Ethereum Virtual Machine (EVM). For every operation that a script can execute there is a special cost, expressed in number of Gas units. The price of one unit of Gas is decided by the miners. Ethereum uses Ether as its internal currency/token. When you deploy a contract, or execute a transaction, the Gas will be taken from the business application account balance into Ethereum.
Gas Limit is the maximum amount of Gas that can be used per block, it is considered the maximum computational load, transaction volume, or block size of a block, and miners can slowly influence that value over time.
(StartGas — RemainingGas) x Gas price = fee paid to miner
RemainingGas x Gas price = refund
*Please note, Gas is synonymous to Gwei where 1 Gwei equals 0.000000001 ETH
How do we strategize these transactions?
We take a look at the process flow for the business and determine which processes would map to blocks. Once we relate each process in the flow to a block, then we determine what the transactional design is for that process. We refer to the document provided by Ethereum (https://docs.google.com/spreadsheets/d/1m89CVujrQe5LAFJ8-YAUCcNK950dUzMQPMJBxRtGCqs/edit?usp=sharing) as to how much each operation will cost and try to create a simple transactional methodology per process.
Also, note that it takes around 132 blocks to write 1MB of data to the blockchain. This should be taken into account to determine how much data will be stored in the blockchain based on continuous increase of users and new blocks, resulting in earnings for generating new blocks.
Once we figure out how much our costs are roughly for these transactions, then we are able to determine licensing fees. Our licensing fees will be little to none as long as our user base increases, we continue to create new blocks and continue mining. Based on this, we can determine how much we save over time with these transactions.
With all of that in mind, using strategy to handle each transaction and finding a balance between on-chain and off-chain transactions is key while still leveraging the decentralized capabilities of blockchain. Figuring out all of these details is currently the bottleneck in many blockchain companies today, the transactional and financial design in blockchain is not yet fully understood in many blockchain companies.
Optimizing this strategy is one step closer in creating a decentralized economy and accelerates the development of blockchain companies.