Can a contract pay its own gas fees?

All of the canonical examples show that the sender (EOA) of a transaction is required to pay the gas fee for the contract execution. How would I go about building a Dapp in which the Dapp held a balance and paid the fees on behalf of the EOA?

The reason for the question is to reduce the barrier to adoption that the need to acquire Eth poses for new end users, or for cases that the end user is (say) an employee accessing a corporate Dapp.

Comments

  • tym4ttym4t Nagata-ku, Kobe-shi, Hyogo-ken, JapanMember Posts: 71 ✭✭✭
    You cannot get a contract to run without paying for the transaction to run it. Having contracts pay for their own execution would be a bad thing as a spammer could wipe out the contract by making repeated calls to it. What you can do is have some ETH in the contract's account balance and have some function in the contract code which looks at the amount of gas used, calculates the amount of ETH, and refund that to the caller.

    A corporate DApp would have to set up a contract that serves as a registry of employee account addresses. The company can then replenish each account with enough Ether for the tasks that they need to perform through a CFO/Treasurer DApp. You can make the user wallets check their own balances and call the CFO/Treasurer DApp when it is running low on funds. The owner(s) of the CFO/Treasurer DApp can then approve the request which transfers enough Ether allowance to the employee's account.

    For end-user type DApps you have a few options. You can have them sign up through a centralized website where they can register their Ethereum addresses but this would be easy to abuse without some kind of underlying identity/reputation system. You can also do what Augur is doing and create your own tokens which users can buy which have and represent some underlying ETH value to run your DApp.

    I've been working on a side project since March 2014 called Croesus which allows you to subsidize your DApp execution costs (cheaper but not free) through display advertising.
  • SmithgiftSmithgift Member Posts: 64
    Unfortunately, there is no way for a contract to pay gas fees, though it could reimburse the sender for running it.

    The issue is that gas is a clue to how long a contract might be running, and therefore it must be specified up front.
  • pinoyyidpinoyyid Member Posts: 17
    thanks for the thoughts.

    As I muse more deeply on this, it seems that the wallet is serving two distinct purposes; as a source of identity, and a source of value. There will be many use cases where it is helpful to decouple these two roles to avoid having to distribute value for an application which is intended to be free, and potentially, mandatory. I'm wondering to what extent whisper can be used to construct some kind of proxy where the end user has an empty wallet, and the value required to execute contracts is held by a proxy DApp.
  • tym4ttym4t Nagata-ku, Kobe-shi, Hyogo-ken, JapanMember Posts: 71 ✭✭✭
    A simple approach is to create a faucet DAO for your DApp where you can serve some targeted advertising to subsidize your cost.

    Perhaps when Swarm becomes available you can drop a set of pre-generated passphrase protected private keys containing some Ether for registered users which the client automatically imports into their account.

    Decoupling identity and value is challenging as you would have to find another way of preventing sybil attacks that wipe you out of Ether from abusive users.

    One thing that one must really consider when making DApps is that the things that work in the client-server world will probably not be applicable to the decentralized P2P world. Websites today are able to reactively block abusive users by IP address but P2P DApps do not have that luxury. I think that as the rest of the world becomes more Ethereum savvy in the hopefully not so distant future having some Ether balance would be seen as natural as having a Twitter or Facebook account. That's really the ideal goal - to have Ether as a fundamental utility token just like mobile phone minutes or internet access.

    One anecdote is something that I have experienced in the Philippines. All the mobile phone service providers there offer "Free Facebook" as part of their phone plan. As it turns out Facebook has made a deal with the phone carriers to subsidize internet usage for customers for Facebook related traffic. It's a win-win for the carrier because this does not affect their already bloated profit margins and oftentimes users don't even realized that in the process of browsing their FB friends that they always end up going to some external website by clicking some link from their FB news feed.

  • pinoyyidpinoyyid Member Posts: 17
    Thanks again for your thoughts. I totally agree that the exciting destination is the "Ether balance would be seen as natural ". It's really a question of what we need to do to bootstrap the journey.

    The Free Facebook initiative was a nice piece of creative thinking. The unfortunate side-effect is that half the population is now transfixed by their "always on" facebook feed :-(
  • ChrJentzschChrJentzsch Member Posts: 17
    There are several ways of doing so. But not quick and easy.
    1.)
    The user could set the gasPrice to 0. Although this transaction would most likely not be picked up by the miners, the Dapp provider could mine all transaction going to his address. But then of course the time it takes for the transaction to make it to the blockchain depends on the mining power of the Dapp provider. This is of course also a bit centralized.

    2.) You can make a smart contract which refunds the miners for including those transactions. Basically allowing them to make a transaction to this contract with a proof that they mined a block and included zero gasPrice transactions to your Dapp. This should result in paying the miner. But then you would need to write a patch for the client and convince all miners to install it.
  • pinoyyidpinoyyid Member Posts: 17
    I like the lateral thinking of both of these approaches...

    On 1, is there a mechanism in the standard client to allow me to filter out only my own transactions, or at least prioritise them? The fact the mining is centralised isn't an issue for the use cases I'm considering.

    On 2, would such a patch be disruptive to normal mining? What I mean by this is, if I wrote such a patch, is there any downside in it being accepted as a pull request and become a configurable feature of the standard client?
  • PranayPranay Member Posts: 58
    With the similar concept, can we also hold gas value and at the time of transaction we can use that?
  • H3g3m0nH3g3m0n Member Posts: 4
    I kind of wonder about a modified version of Ethereum.

    One with a centralized authority distributing Ether to registered users daily up to some cap (an amount more than you would be likely to use for your app, but not enough to allow a DOS against the network).

    Maybe have trading disabled (although technically still possible because people could share wallets/keys/accounts/whatever but at least it's made harder). Make it an embeddable library and different apps could setup their own networks so they don't have to trust a central authority.

    Of course then it would possible for the central authority to lock down accounts and censor things that way. But on the plus side it's better than most services offered that keep all your data.

    Of course there is no mining rewards but if you setup your app to automatically do background mining just to keep the network ticking over. And keep track of the users hashrate to ensure no one sets up a cluster to try and down the network (but you have to be sure that your identity system isn't going to get abused).

    The main advantage would be no barrier to entry since you don't need to buy Ether.
  • tomachitomachi Member Posts: 3
    First, distribute your tokens, *then* allow your customers to exchange those for Ether. This prevents the abuse / Sybil attacks mentioned earlier I would think, since you can control where those tokens are coming from. That's my plan. The GUI can automatically do this, and I can give out free tokens early on.
Sign In or Register to comment.