What is approve and allowance method?

0 votes

I have this following code that I saw in an example and I am trying to understanding what it does. I came across two methods approve and allowance and I am not understanding what it does. Can you explain?

The code is as follows:

contract Token {
    uint256 public totalSupply;
    function balanceOf(address _owner) constant returns (uint256 balance);
    function transfer(address _to, uint256 value) returns (bool success);
    function transferFrom(address _from, address _to, uint256 value) returns (bool success);
    function approve(address _spender, uint256 _value) returns (bool success);
    function allowance(address _owner, address _spender) constant returns (uint256 remaining);
    event Transfer(address indexed _from, address indexed _to, uint256 _value);
    event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}
Jul 29, 2018 in Blockchain by slayer
• 29,170 points
28 views

1 answer to this question.

0 votes

approve(): This method is used by one user to give permission to use some of its tokens by another user.

Suppose there are two users A and B. A has 100 tokens with it and wants to let B use 50 tokens from its balance(balance of A:100). So A uses the approve method to approve B to use 50 tokens from it.

When A calls approve(address(B), 50) , B is allowed to use 50 tokens from 100 tokens of user A.

allowance(): This method is used by an user to check how many tokens some other user has allowed it to use.

B calls allowance(address(A), address(B)) to know how many tokens has A allowed B to use (from A’s tokens). In this case, the result will be 50.

answered Jul 29, 2018 by digger
• 26,550 points

Related Questions In Blockchain

+1 vote
1 answer

What is the difference between if() and require() statement in solidity??

If() and require() have separate functions and ...READ MORE

answered Apr 18, 2018 in Blockchain by Shashank
• 10,350 points
450 views
+1 vote
2 answers

What is a blockchain and ethereum?

Some of the use-cases are: Healthcare Medical records are ...READ MORE

answered Aug 9, 2018 in Blockchain by Omkar
• 67,660 points
67 views
0 votes
2 answers

What is the difference between full node and partial node?

We need different types of nodes to ...READ MORE

answered May 30 in Blockchain by Sourav kumar
217 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Invalid Batch or signature in Savtooth

This will solve your problem import org.apache.commons.codec.binary.Hex; Transaction txn ...READ MORE

answered Aug 1, 2018 in Blockchain by digger
• 26,550 points
83 views
+1 vote
1 answer
0 votes
1 answer
0 votes
1 answer

What is transientMap in node.js and getTransient in chaincode?

TransientMap: TransientMap  contains data that might be used to ...READ MORE

answered Jul 13, 2018 in Blockchain by digger
• 26,550 points
219 views