使用etherjs库旧版本可以达到此效果,evm的链都可用。注意, 这里的ethers版本为5.7.2,6.x版本是不行的
const ethers = require('ethers');
// 实例化provider
const provider = new ethers.providers.JsonRpcProvider("https://polygon.llamarpc.com");
const ABI = []
(async () => {
// 替换为自己的hash
const tx = await provider.getTransaction("hash code");
const inter = new ethers.utils.Interface(ABI);
const decodedInput = inter.parseTransaction({ data: tx.data, value: tx.value});
console.log('decode', {
function_name: decodedInput.name,
from: tx.from,
to: decodedInput.args[0],
erc20Value: Number(decodedInput.args[1])
});
console.log('rs', decodedInput)
})()