Understanding Gas Price & Gas Limit [TokenGen Tutorial]

Understanding gas price & gas limit [TokenGen tutorial]

Since several of our TokenGen users have recently asked about gas limit and price, I thought I’d write a short guide on the matter. When it comes to token crowdsale contracts, and more specifically, the ones generated by TokenGen, you need to know what gas limit you should set and also, distinguish the difference between gas limit and gas price.

What is Gas Limit & Gas Price?

In Ethereum, gas limit and gas price refer to transaction fee that comes with each transaction made on the blockchain. Long story short, the gas limit is the maximum amount of gas you are inclined to pay for the transaction and gas price is the amount of ETH you want to pay for a single gas unit. So, the maximum transaction fee you are willing to pay is a simple multiplication of the gas limit and the gas price.

For example, if I set the gas limit to 200,000 and the gas price to 5 gwei, then the maximum transaction fee I can pay on this example transaction is 1,000,000 gwei (1 million gwei). 1 gwei is equal to 1,000,000,000 (1 billion) wei. Wei is the fundamental currency metric in Ethereum and is equal to 0.000000000000000001 (zero with 17 zeros behind the decimal and 1 at the end) worth of ETH. So based on this, the maximum transaction fee I can pay is 0.001 ETH, which is currently valued at around $0.1345 USD.

But how do you determine what gas limit you should set? You can determine the gas price with relative ease thanks to ETH Gas Station for example, but what about the gas limit? Well, usually, the wallet you are using to send the transaction will automatically set a viable gas limit. The wallet bases this gas limit on the operations that will be executed once you send the transactions. Naturally, more operations equals more gas limit.

However, sometimes, the wallet you are using cannot determine the gas limit on its own. For instance, when you are sending ETH to a token crowdsale contract, your wallet most probably won’t know how much gas limit to set and will set the default 21,000. Of course, that is too low and the transaction will fail. For token crowdsale contracts, usually, around 200,000 gas limit is the recommended value.

It is important to mention here that, setting 200,000 gas limit doesn’t mean that the transaction will use exactly 200,000 gas units. It will use exactly the amount of gas it needs. The gas limit is simply a cap you set that determines the maximum amount you are willing to pay. So even if you set 5,000,000 as a gas limit, and only 100,000 is used for the transaction, you won’t be charged for the “remaining” 4,900,000 gas units. That’s pretty much how gas limit and gas price work on the Ethereum blockchain. Now let’s get more specific.

Gas Limit & Price in Token Crowdsale Contracts

As mentioned, most wallets won’t be able to determine how much gas limit to set when you are sending ETH to a token crowdsale contract. So, the recommended value to set, specifically for TokenGen-generated contracts, is 200,000. That is two hundred thousand, not twenty thousand. Why the extra clarification? You’d be surprised how many people mistakenly use 20k instead of 200k for the gas limit and thus miss out on participating in a particular token generation event.

So, once you deploy your TokenGen smart contracts, make sure to let your community know that, they need to set a gas limit of at least 200,000 when sending ETH to your fundraiser contract. How do you manipulate the gas limit? That is usually a functionality provided by the wallet being used. For instance, MetaMask provides this option via the small Settings icon in the Gas Fee input when creating a new transaction:

MetaMask Customize Gas Limit & Price


On a closing note, we are looking into a way of implementing the recommended gas limit somewhere into the TokenGen UI, so that your community knows what to do when they are about to participate in your token crowdsale, even if you forgot to tell them about the gas limit situation. But, that will probably come with the upcoming landing page feature – more on that soon. Until then, make sure to notify your community to set the appropriate gas limit when participating in your token generation event.