0

I need to suscribe to Transfer events of couple of different ERC20s in order to catch transfers to my contract. And here is the question: to catch all those events I need to create instance of each contract, can I do this using standard ERC20 abi for each of this contract or it has to be abi dedicated to exact erc20 smart contract?

0

Yes, you can use the ABI of a standard ERC20, this should work well as long as the tokens really follow the standard, which is true in most cases.

| improve this answer | |
0

If you're interested only in the standard ERC20 Transfer events, then even a subset of the ABI is sufficient. For example, if you implement it in Javascript, then you can simply use this:

const ABI =
[
    {
        "anonymous": false,
        "inputs":
        [
            {"indexed": true , "name": "from" , "type": "address"},
            {"indexed": true , "name": "to"   , "type": "address"},
            {"indexed": false, "name": "value", "type": "uint256"}
        ],
        "name": "Transfer",
        "type": "event"
    }
];

const contract = new web3.eth.Contract(ABI, address);
contract.getPastEvents("Transfer", {fromBlock: ..., toBlock: ...}).then(events => {
    for (const event of events) {
        console.log(event.returnValues.from);
        console.log(event.returnValues.to);
        console.log(event.returnValues.value);
    }
});

You can also choose freely the input parameter names, i.e., replace from, to and value above.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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