1

Token approval checker of block chain explorer such Etherscan can only find approval for normal address instead of smart contract address. You can answer this question in two ways:

  1. Is there any tool to find token approval of a smart contract address?
  2. What is the algorithm to find it? Allowance can be got by calling erc20_token.allowance(owner, spender), the remaining question is how to find possible spenders, maybe through history transactions of the smart contract?

1 Answer 1

0

1- Is there any tool to find token approval of a smart contract address?

I think Etherscan can be used to find the "Approval" events: https://etherscan.io/address/0xdac17f958d2ee523a2206206994597c13d831ec7#events

2 - What is the algorithm to find it?

It can be this:

        await erc20Contract.getPastEvents('Approval', {
            filter: {spender: marketplaceContract},
            fromBlock: 0,
            toBlock: "latest",
        }, function(e, events){
            if(!e){
                for(let i=0;i<events.length;i++){
                    console.log(events[i])
                }
            }
        });

3 - How to find possible spenders, maybe through history transactions of the smart contract?

Yes, through the logs:

            await erc20Contract.getPastEvents('Approval', {
                fromBlock: 0,
                toBlock: "latest",
            }, function(e, events){
                if(!e){
                    for(let i=0;i<events.length;i++){
                        console.log(events[i].returnValues.spender)
                    }
                }
            });
2
  • Without having abi of the contract is it possible to get details from getPastEvents? Sep 19, 2022 at 16:55
  • You need to know the name of the event at least. In this example, the event is "Approval". You can check the event name on an explorer and try to get the events using the code above. Knowing the event name, you can know the parameters of the event. Sep 20, 2022 at 19:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.