I have a ERC-20 contract with the main function´s. I generate 1000000 coins and I´m trying to do the following:

  • There are 3 user´s (a, b, c)
  • The c user have 10 coins, and wants to aprove to the b account to be able to manage 5 coins of the c user. For send to the a account.

I make this:

  • Unlock accounts
  • Send 10 coins to the c account
  • Call to the approve function with the account c address and the quantity of coin´s

Now I don´t know what I have to do. Because in the approve function I approve 5 coins to the c account. But I don´t specified that the b account will be able to manage that coins.

enter image description here

Once that is made i have to call to the transferFrom and give like parameter the the b account (allowed account), the a account (receiver) and the quantity

  • 2
    "But I don´t specified that the b account will be able to manage that coins" - well, what's stopping you from doing that (i.e., passing the address of b to function approve)? – goodvibration Dec 20 '18 at 15:10
  • If im not wrong. The approve function have two parameters. spender and value. there is another value like allowedAccount?' for example. – UnexpectedCharacter Dec 20 '18 at 15:15
  • 2
    b is the spender, and you should use (the private key of) c in order to call the function. – goodvibration Dec 20 '18 at 15:19
  • 1
    After all, it is c who is approving b to make transaction on his (or her) behalf. And what better way is there to do so, than using the private key of c in order to approve something like that? – goodvibration Dec 20 '18 at 15:20
  • 1
    No, you should put the address of b there, and call the function with account c (i.e., sign the transaction with the private key of c, or unlock account c on the node and let the node sign it for you). – goodvibration Dec 20 '18 at 15:23

Ok. I am not sure why user a is relevant but I will assume it is the address used to deploy contract. The following is the flow you should follow;

  1. Deploy contract with address a
  2. Copy address b
  3. Using address c, trigger the approve function and paste address b as the spender and write the amount of tokens you want to approve
  4. Using address b, trigger the transferFrom function with the inputs: the c address, any other address, the amount of tokens you want to transfer. (this corresponds to: from, to, amount)
  5. You should see the transfer happen if the amount transferred or less has been approved before.

I hope this helps


You can ”approve” your account spending only.

Whenever you approve Bob for an amount, you are saying to Bob: I give to you the right to spend some money from my wallet (you approved the amount for Bob).

Then Bob is allowed to send that money approved from your wallet to a third person using transferFrom. From your wallet to the third person’s wallet. Or to Bob’s own wallet, If Bob prefers.

Bob pays the gas for the transfer.

This is the concept of allowance.

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.