...by Daniel Szego
"On a long enough timeline we will all become Satoshi Nakamoto.."
Daniel Szego

Monday, December 25, 2017

Solidity and Truffle Tips and Tricks - estimate gas usage

Estimating the gas usage is a critical part of every Ethereum Smart Contract. If you use Truffle and test rpc, the easiest way is to write a unit test for each critical function as a transaction. If a function is separated into several subcalls, it is a good idea to cover each of the sub-function separately from an individual unit test as an individual transaction. Having the individual tests, you can start a new console windows with truffle develop --log, in which you can see the gas consumption of each transaction. As gas consumption might be dependent from data, it can be a good idea to measure each transaction with several possible data input.