2
votes

Is it possible to store gas that is not used inside a contract, so it can be used at a later time (presuming it is possible to require a certain amount of gas calling a function)?

I am trying to write a contract that requires user input and does something based upon that input at a later moment in time that will require gas.

As it does not sound really attractive to pay that gas out of the contract owners pocket I am looking for a way to make the user of the contract pay for the gas it needs to complete the request.

2

2 Answers

2
votes

In fact, it is really possible to store gas in a contract for later use.

There are some operations in EVM that can return some gas that was payed before:

  • SSTORE: changing storage value from non-zero to zero releases 15000 gas
  • SELFDESTRUCT: destroying contract releases 24000 gas

That means that e.g. storing some value requires 20k gas, but deleting it form storage requires only 5k gas and releases 15k gas for later usage in the same transaction. Actually this is a reward for clearing up blockchain storage.

You can get more details by searching "refund" in Yellowpaper.

There is GasToken project that uses this very feature to store gas in contract when it is cheap and release (and use) when it is expensive.


To be clear, I don't think this allows user to issue transactions without paying gas at all.

1
votes

Seems like you have mixed up a little bit the meaning of gas. The gas is the Ether you have to pay to have your transaction mined. The gas is always paid by the address that calls the function(Contract) and not from the Contract itself or the owner of the Contract so it doesn't come out of the owners pocket. Also gas is basically ether so "storing gas" is to store Ether in a contract but you cannot store the gas that is used to mine the transaction. If you want to store Ether you have to send Ether to the Contract or have the users send Ether when they call a function.