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

Thursday, July 28, 2022

[FIXED] How to get current approval allowance in Ethereum

 July 28, 2022     blockchain, ethereum, go-ethereum     No comments   

Issue

After one approve is made, I want to know how to get current approval allowance(from an address, to a specified contract and gateway), in json-rpc way. e.g. like eth_call?


Solution

The to field of the call is the token contract, and the data param is ABI-encoded signature of allowance() function followed by its arguments. eth_call also requires to specify at which block you're requesting the data - you can use the "latest" value for the current block

curl -X POST \
--url "<your_node_url>" \
--data '{"jsonrpc":"2.0","method":"eth_call","params":[{"to":"0xdAC17F958D2ee523a2206206994597C13D831ec7","data":"0xdd62ed3e00000000000000000000000086987cca9f86da6b4d8a805c1ebd4130ae120a24000000000000000000000000b2723beacce4bc54f23544343927f048cef6bd5a"}, "latest"],"id":1}'

Docs: https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_call


I used this JS snippet to build the data param value:

const data = web3.eth.abi.encodeFunctionCall({
    name: 'allowance',
    type: 'function',
    inputs: [{
        type: 'address',
        name: 'from'
    },{
        type: 'address',
        name: 'to'
    }]
}, [
    "0x86987cca9f86da6b4d8a805c1ebd4130ae120a24",
    "0xB2723BEacce4BC54F23544343927f048CeF6bD5A"
]);
console.log(data);


Answered By - Petr Hejda
Answer Checked By - Willingham (PHPFixing Volunteer)
  • 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