1

I want the address of the wallet interacting with the smart contract (the 'from' address in the tx receipt). I can get the smart contract event and parse the event log in the below code but ideally I don't want to have to make another call after getting the smart contract event log. Is it possible to get the address interacting with the smart contract straight from the event log itself?

// use a http provider
async function parseLog(log){
    const tx = await web3.eth.getTransactionReceipt(log.transactionHash)
    console.log(`from: ${tx.from}`)
}
// use a ws provider
var subscription = web3.eth.subscribe('logs', {
    address: address
}, function(error, result){
    if (error){
        console.log('error: ' + error)
    }
})
.on("connected", function(subscriptionId){
    console.log("connected " + subscriptionId);
})
.on("data", function(log){
    // publish something to the subscriber
    parseLog(log)
})
.on("changed", function(log){
    console.log("changed " + log);
});

1 Answer 1

1

No, this data isn't saved in logs, unless a contract explicitly emits it as one of its parameters.

Here's an example of a log event -

"logs": [
        {
            "transactionIndex": 54,
            "blockNumber": 28164257,
            "transactionHash": "0x7ffc8534b6aa57decfc21c9325eff0c6d8e94e220abb6394cfe0a481ae0fa794",
            "address": "0xf28164A485B0B2C90639E47b0f377b4a438a16B1",
            "topics": [
                "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
                "0x0000000000000000000000008ecbc9b0741c000fd7aae9cb559e5eee1d1883f3",
                "0x000000000000000000000000ed5c4150f867b278866bbad33e947287cc5a2ef1"
            ],
            "data": "0x000000000000000000000000000000000000000000000000001546c9a6ed714e",
            "logIndex": 356,
            "blockHash": "0xf7f71edf1dc9b4b1128a6de74c289f2b54f630e5725f617fcab2f84a7ba275ca"
        },
    ...
]
  • address is the emitting contract
  • topics are event signature and indexed parameters
  • data contains the non-indexed parameters

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.