Search code examples
ethereumsoliditycryptocurrencyetherevm

Do I need to pay gas fees to distribute my ethereum based crypto?


If I were to create my own Ethereum based crypto token named "ExampleCoin" with a supply of 1,000,000,000 and decided to distribute it to users for playing my game, would I need to pay a gas fee each time I give a user some ExampleCoin?

And if I had an in game store where users can make purchases with ExampleCoin, would a gas fee need to be paid in order to send ExampleCoin from the user to the game?


Solution

  • Gas is like gasoline to the Ethereum network; whenever we interact with the blockchain and affect its state, we must pay the fee required to perform the computations and process the transaction [1]. Each action such as storing values, sending tokens, adding integers etc. has associated cost in gas units [2]. The total gas cost for a transaction is multiplied by a gas price [3] to get the gas, or transaction, fee.

    The transaction in which the ExampleCoin contract allocates some ExampleCoin tokens to a user, will be initiated by the user who will have to pay the required gas fee. Thus, it is the user who will initiate the transaction which will allocate the tokens to him, and thus he will pay the gas fee.

    Similarly, when the user makes purchases with ExampleCoin, he is making a transaction affecting the state of the blockchain and thus incurring gas cost; so, he will have to pay the gas fee.

    The bottom line is that whoever makes a transaction will have to pay the required gas fee. In this case, it would be the user, and not your contract, who pays the gas fee.

    It is because of the increasing gas prices and thus transaction fees on the Ethereum network that solutions like sidechains, and other blockchains focusing on low transaction fees such as Solana have been developed. Thus, as a smart contract/ dapp developer, one has to comprehensively ascertain the business logic of one's application and decide which network to deploy it on, keeping the end user's experience in mind.

    [1] See these explainers on gas and transactions: https://ethereum.org/en/developers/docs/gas/ https://ethereum.org/en/developers/docs/transactions/

    [2] See page 27 of the Yellow Paper for a list of operations and associated gas cost in gas units. For example, the base gas cost for every transaction is 21000 gas units: https://ethereum.github.io/yellowpaper/paper.pdf

    [3] This is the amount in ETH we are willing to pay to the miner, per gas unit, as incentive to include our transaction in the next block. The higher the gas price, the more quickly our transaction is picked up by miners and mined.