0

I am trying to decode transfer log to get the addresses to and from, and potentially the value but most important address from and to.

const subscribe = () => {
    subscription = web3.eth.subscribe('logs', {
    }, (error, data) => {
        if (!error) {
            //console.log("Address: " + data.address);
            //console.log(data);
            return;
        }
        console.log(error);
    }).on("data", (data) => {
        //console.log("Address: " + data.address);
        console.log(data);
        console.log(web3.eth.abi.decodeLog([
            {
                "indexed": true,
                "name": "from",
                "type": "address"
            },
            {
                "indexed": true,
                "name": "to",
                "type": "address"
            },
            {
                "indexed": false,
                "name": "value",
                "type": "uint256"
            }
        ], data.address, data.topics));
        var isTransfer = web3.utils.keccak256('Transfer(address,address,uint256)');
        if (data.topics !== null && data.topics[0] === isTransfer) {

            if (data.topics[1] === undefined && data.topics[2] === undefined) {
                console.log(data);
                return;
            }
            console.log(data.topics[1]);
            console.log(data.topics[2]);
        }
    }).on("changed", (data) => {
        //console.log("CHANGED");
        //console.log(data);
    });
}

I am sure I am missing something simple at this point I think. Looking for a little guidance, was just confused a little bit by the documentation here.

Your Answer

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

Browse other questions tagged or ask your own question.