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 30, 2018 in Blockchain by slayer
• 29,360 points

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 30, 2018 by digger
• 26,740 points

Related Questions In Blockchain

0 votes
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,400 points
+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
• 69,230 points
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 31, 2019 in Blockchain by Sourav kumar
0 votes
1 answer
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
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,740 points
+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,740 points
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP