I am creating a nodejs script using Ethers that is broadcasting new transactions. I can not find out how to get information about token address. transaction.data
is encoded. I am enclosing the below example result. I have all information I need, except token address. I have tried some ABI decoding methods for hours without luck. What would be proper way to get token name from the transaction?
var ethers = require("ethers");
var url = PROVIDER_URL;
var init = function () {
var customWsProvider = new ethers.providers.WebSocketProvider(url);
customWsProvider.on("pending", (tx) => {
customWsProvider.getTransaction(tx).then(function (transaction) {
console.log(transaction);
});
});
customWsProvider._websocket.on("error", async () => {
console.log(`Unable to connect to ${ep.subdomain} retrying in 3s...`);
setTimeout(init, 3000);
});
customWsProvider._websocket.on("close", async (code) => {
console.log(
`Connection lost with code ${code}! Attempting reconnect in 3s...`
);
customWsProvider._websocket.terminate();
setTimeout(init, 3000);
});
};
init();
Results:
{
hash: '0x2cf879ab1a0419f8f489db54ce383a03509a6eae25e17b049559e030ccb04a71',
type: 2,
accessList: [],
blockHash: null,
blockNumber: null,
transactionIndex: null,
confirmations: 0,
from: '0xfB652438ecd86f861084Eacfd851F19b30d8e031',
gasPrice: BigNumber { _hex: '0x5968609d', _isBigNumber: true },
maxPriorityFeePerGas: BigNumber { _hex: '0x59682f00', _isBigNumber: true },
maxFeePerGas: BigNumber { _hex: '0x5968609d', _isBigNumber: true },
gasLimit: BigNumber { _hex: '0x02fe32', _isBigNumber: true },
to: '0x4648a43B2C14Da09FdF82B161150d3F634f40491',
value: BigNumber { _hex: '0x2386f26fc10000', _isBigNumber: true },
nonce: 33,
data: '0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000063e2e33000000000000000000000000000000000000000000000000000000000000000020b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000002386f26fc100000000000000000000000000000000000000000000000000000022580dc6705aad00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002bb4fbf271143f4fbf7b91a5ded31805e42b2208d60001f41f9840a85d5af5bf1d1762f925bdaddc4201f984000000000000000000000000000000000000000000',
r: '0x649b6e48f0696d5c4799b20cf08ec28219be079d0c4c8b80322e86b2aa29d332',
s: '0x26b3859fec9f7c36f71630159f0c154584682a751d7620eecb7d860ae01da292',
v: 0,
creates: null,
chainId: 5,
wait: [Function (anonymous)]
}