1

My Usecase is to get transaction hash and show from which to which wallet a NFT was transferred. but when i use getTransaction of web3.js it returns me contract address in to field instead of wallet/new owner address

EDIT this is what im doing right now (just for testing purposes)

 console.log(await web3.eth.getTransaction("0x93dfc88f391fc68d8fe8e75e6c37dbb8011a3bf872433909766341953464ee43"))

enter image description here this is getTransaction responce

enter image description here this is info given by ether scan

now as you can see in GetTransaction response we get contract address but what i want the to from tokens transferred

4
  • Please show us code and what you tried Commented Nov 18, 2021 at 14:49
  • You have to use the logs from the transaction's receipt. Every ERC-721 transfer generates a log entry with sender, recipient and amount.
    – Ismael
    Commented Nov 19, 2021 at 4:06
  • @WilliamEntriken Edited
    – Shozab
    Commented Nov 19, 2021 at 6:04
  • @Ismael sure i'll look into this , Thanks
    – Shozab
    Commented Nov 19, 2021 at 6:15

1 Answer 1

1

One transaction can have an arbitrary number of ERC-721 transactions. Each transaction will emit a Transfer event.

The typical way to do it is:

var contract = new web3.eth.Contract(abi, contractAddress, {from: account});
contract.events.Transfer(
  {filter: {from: account}}, fromBlock: 0},
  function(error, event){ console.log(event); }
)

This can be filtered per block, TX, accounts, etc.

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.