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,040 points
17 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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
• 27,620 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,330 points
227 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
• 65,850 points
40 views
0 votes
1 answer

What is the difference between full node and partial node?

There are two types of nodes in ...READ MORE

answered Jul 11, 2018 in Blockchain by whatsinname
• 280 points
79 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
• 27,620 points
41 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
• 27,620 points
145 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.