6

With regular ERC20 tokens we have method approve(to, amount) and so I can approve to someone to take specified amount of my tokens later with transferFrom(from, to, amount).

Is there any way to approve Ether to be taken from my account?

3 Answers 3

4

You could do it by coding pretty much the same logic as the token does for it's own balance.

  1. A deposit function takes ether from msg.sender and stores it in the contract while registering the amount deposited by that address in a mapping state variable.

  2. An approve function would set how much ether the contract is allowed to transfer from the origin address.

  3. A transferFrom function would modify the _from account balance and _to account balance accordingly (up to the amount that was approved).

  4. Here's a main difference with the token logic. You would have to have a withdraw function that allows the msg.sender to reduce its balance and generate an Ether transfer from the contract to msg.sender. (This would be done to prevent possible DoS attacks on the contract).

1
  • 1
    Can you elaborate on the "prevent possible DoS attacks" part?
    – Daniel Que
    Feb 2, 2018 at 9:25
0

The only way that I have found is to create a Smart Contract and to put ether on it. Smart Contract needs to have approve method for recipient like for ERC20 token. So recipient can get specified amount of ether. Not yet tested but in theory sounds possible.

0

Just use WETH.

As previous answers mentioned, Ether does not support approve natively - you have to wrap ETH in an another Smart Contract.

WETH is an common standard, thoroughly audited, optimized and used by biggest projects in the industry. You can check its source code here.

Your Answer

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

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