1

I have a contract that returns event data including the sender's address:

event Result(
    address indexed _walletAddress,
    string _name,
    uint256 _amount
)

And in my Node.js app I try to capture the address:

const address = result[0].topics[1];

But for some reason the address contains extra "00000000000000000000000":

0x0000000000000000000000001fcda174c13691ef3c13fcee042e0251452c0f8s

How can I extract the address in the correct form?

0x1fcda174c13691ef3c13fcee042e0251452c0f8s

Any help is greatly appreciated

1
  • 1
    The reason for the extra zeroes is, that ethereum stores everything in 32bytes. An Ethereum Address is 20bytes in length, hence the extra zeroes in the output. Feb 19 '20 at 6:48
1

You can achieve that by using web3.eth.abi.decodeLog(inputs, hexString, topics);. The first parameter inputs must include the properties of the event from your smart contract, second one hexString is the bytecode of the event and the third topics is array containing the topics. Read more here.

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.