hardhat task로 만든 txHash로 transaction details 얻어서 ERC20 Transfer() 이면 정보 출력.
task("trasactionDetails", "Get the transaction deatils")
.addPositionalParam("txHash", "Transaction Hash")
.setAction(async (taskArgs, hre) => {
const provider = ethers.provider;
const transaction = await provider.getTransaction(taskArgs.txHash);
console.log(transaction);
if (transaction.value === 0n) {
if (transaction.data.slice(0, 10) === "0xa9059cbb") {
console.log("---- ERC20 Transfer -------------------------");
await hre.run("parseERC20TransferData", { data: transaction.data });
}
}
});
task("parseERC20TransferData", "Parsing")
.addPositionalParam("data", "Transacton Data")
.setAction(async (taskArgs) => {
const abiCoder = new ethers.AbiCoder();
const decodedData = abiCoder.decode(['address', 'uint256'], "0x" + taskArgs.data.slice(10));
const to = decodedData[0];
const value = decodedData[1].toString();
console.log('To Address:', to);
console.log('Token Amount:', ethers.formatEther(value));
});