0

For instance, say clicking on a button will perform some type of action and it charges the user 1 token, but doesn't show any pop-up dialogs.

I don't want a Metamask window opening up to submit a transaction everytime a tx might occur, since it could ruin the user experience. The user would agree to the terms and conditions allowing the dapp to consume tokens without their explicit permission of course.

I just want to know, is this possible with smart contracts and how?

1
  • I think one could write such a contract. You'd have a method on the contract restricted to being called by you or one of your agents.
    – lungj
    Aug 25, 2017 at 22:53

1 Answer 1

2

ERC20 has a function called approve(address _spender, uint _value) which allows a user to give permission to your address or contract (_spender) to debit your token up to the specified amount (_value). Once approved, you can transfer funds on their behalf using transferFrom().

So have your user approve a single transaction in Metamask giving your address or contract permission to debit their funds, then you can perform any future operations on their behalf without them needing to approve another transaction through Metamask.

Note that you will still need to somehow get a transaction to the network to debit these funds; The obvious way to do it would be to run a server-side process listening for user actions, somehow validating that they really came from the user in question and sending transactions for them behind the scenes.

PS. If the user is going to be clearing you to debit funds used in many small transactions in any case, you may also want to look at different approaches, in particular state channels, which don't require either them or you to keep sending transactions to the blockchain. For example, see this proposal for fast, verifiable off-chain gambling.

8

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.