I have tried using web3.eth.getTransaction to retrieve the receiver address. However, the return result "to: 0x55d398326f99059fF775485246999027B3197955" is the token address instead of the receiver address. The receiver suppose is "0xdd7dac811ad166b30e97c37bc450d7851e5c6971". Anyone got faced this issue before?
below is my source code:
let provider = new Web3.providers.HttpProvider('https://bsc-dataseed2.binance.org/');
let web3 = new Web3(provider);
let testing = await web3.eth.getTransaction('0x12bc57ac6f0056588af06b033848b453c3ed0ee4f3a1cc8a7550a617d82ac1e5')
console.log(testing)
Response return:
{
blockHash: '0x0ff3577a6d5f755ee01c3b24b8146ad424ca501ebb4d046ae978e02ac3ddda1c',
blockNumber: 22335057,
from: '0x0EdeF9ef3088a71bdAf43b5dE9E113789d5f58BF',
gas: 51115,
gasPrice: '5050000000',
hash: '0x12bc57ac6f0056588af06b033848b453c3ed0ee4f3a1cc8a7550a617d82ac1e5',
input: '0xa9059cbb000000000000000000000000dd7dac811ad166b30e97c37bc450d7851e5c69710000000000000000000000000000000000000000000000056bc75e2d63100000',
nonce: 6,
to: '0x55d398326f99059fF775485246999027B3197955',
transactionIndex: 18,
value: '0',
type: 0,
v: '0x93',
r: '0x2d426a97974e354c526be2a0ca680da98a33b7c7fe166aa2edecd616ff376f8f',
s: '0x7cdf297d1f1f2c8ba62d591857d1f0c5e65ba0e440fe5448527df42ee323f3c9'
}
You need to use getTransactionReceipt and decode logs get the receiver's address.
<script src="https://cdnjs.cloudflare.com/ajax/libs/web3/1.8.0/web3.min.js"></script>
<script>
async function getReceipt() {
let provider = new Web3.providers.HttpProvider('https://bsc-dataseed2.binance.org/');
let web3 = new Web3(provider);
let receipt = await web3.eth.getTransactionReceipt('0x12bc57ac6f0056588af06b033848b453c3ed0ee4f3a1cc8a7550a617d82ac1e5')
let data = web3.eth.abi.decodeParameters(
[
{ type: 'address', name: 'receiver' },
],
receipt.logs[0].topics[2]
);
console.log(data.receiver)
}
getReceipt();
</script>