Is it possible for a contract to pay the gas costs (or part of it) that result from the contract being called? Or does the sender of a message always pay the resulting gas costs no matter what?
Sign up
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
|
|
|
At present the user initiating the transaction must pay the fee. However Serenity is likely to enable 'contract pays' schemes. (See Vitalik's blog post here) A possible work around is a contract which refunds the sender however this would still require the user to hold some Ether and might allow malicious parties to repeatedly call the contract to deplete its funds. |
|||||||||||||
|
|
No, a sender with zero ether cannot "ask" a contract to pay for the gas costs. A sender with zero ether cannot even send a transaction. More details: The sender of a transaction must have enough gas to cover execution of the transaction. That gas is required even before a contract can even be called. Once the gas requirement is met (so that the transaction runs fully without running out of gas), the called contract can send the sender whatever amount of funds the contract holds: the net behavior is that the sender can end up with more ether than they started with, but that is different from the contract paying the gas. It's like you can drive to the bank to get money, but you need fuel first to be able to drive to the bank: the bank can't send you fuel money before you drive to the bank. There is ongoing discussion here for a future release (Serenity) that can change this behavior. |
||||
|
|
|
Not all calls on a contract need gas. It is the so called "dry-run". https://github.com/ethereum/go-ethereum/wiki/Contracts-and-Transactions#interacting-with-contracts
So it is possible to provide a method in a contract to users for zero gas costs - in the example above it is the multiply function. |
|||||
|
|
Not at present but is currently being discussed with an EIP. Gavin Wood says that there is a way to do it presently but from my understanding it's something of a hack. |
|||
|
|
|
The caller of a contract function will need some gas, but you could minimize the gas needed by having the contract immediately call an external function to do the work: In Solidity:
Here the contract is supplying gas from its own reserves to run the |
|||||||||||||||||
|