我尝试过使用web3.eth.getTransaction来检索接收方地址。然而,返回结果";至:0x55d398326f99059fF775485246999027B3197955";是令牌地址,而不是接收器地址。接收者假设是";0xdd7dac811ad166b30e97c37bc450d7851e5c6971";。以前有人遇到过这个问题吗?
以下是我的源代码:
let provider = new Web3.providers.HttpProvider('https://bsc-dataseed2.binance.org/');
let web3 = new Web3(provider);
let testing = await web3.eth.getTransaction('0x12bc57ac6f0056588af06b033848b453c3ed0ee4f3a1cc8a7550a617d82ac1e5')
控制台日志(测试(
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'
}
您需要使用getTransactionReceipt和解码日志来获取接收方的地址。
<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>