PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, September 25, 2022

[FIXED] what approve and allowance methods are really doing in ERC20 Standard?

 September 25, 2022     blockchain, erc20, ethereum, smartcontracts, solidity     No comments   

Issue

The problem is what allowance and approve are really doing?

And what is _spender and what is it doing?

Is there anybody who can explain it to me?

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);
}

Solution

what allowance and approve are doing really?

Let's assume we have user A and user B. A has 1000 tokens and want to give permission to B to spend 100 of them.

  • A will call approve(address(B), 100)
  • B will check how many tokens A gave him permission to use by calling allowance(address(A), address(B))
  • B will send to his account these tokens by calling transferFrom(address(A), address(B), 100)


Answered By - Roman Frolov
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing