3

I was going through ERC20 lately and came across 2 level transfer protocol:

  • approve - Allow receiver to debit x tokens in n transcations
  • transfer - Transfer y tokens: y * n <= x

Why this was not implemented as 1 transaction, i.e. transfer x tokens to receiver wallet, as opposed to 2-level protocol (allow + transfer)? This leads to 2x usage of Eth gas.

6

It's not quite like that. There are two different workflows.

  1. An owner of tokens, A, can transfer his/her tokens to someone else's account using the transfer function. Only a single call is needed for this.

    Token owner A executes transfer(B, n), then A's balance decreases by n, and B's balance increases by n.

  2. In addition, the owner of tokens can also authorise someone else to transfer tokens from his/her account to any other account. This requires two calls.

    Token owner A calls approve(B, m). B can now transfer up to m tokens out of A's account using the transferFrom function: transferFrom(A,B,n), to move n tokens (<=m) to B's own account, or transferFrom(A,C,n) to move them from A's account to C's account.

So it all makes a kind of sense. I suspect the approve/transferFrom workflow isn't used a great deal, though.

  • Hi, I'm new in dapp. I tested this 'transfer' function on front end javascript dapp using web3 contract abi api. but there is additional parameter like '{from: accounts[3]}'. How this can be work? transferring anyone's token to any others – yountae.kang Oct 23 '18 at 1:44
1

Based on the discussion for EIP20, approve and friends are used to enable another contract/account to transfer tokens while transfer is used by the owner to transfer tokens.

Suppose you have 10 ChazTokens and you wish to allow me to transfer 1 of them; you can approve my account to transfer a token and then I can use transferFrom to move one token at a time, whenever I want (you'd use approveOnce to let me do it only once). Note that in this case, there are two separate callers: you and me. This is why we use two functions here.

You can simply move your own tokens using the transfer function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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