I'm fetching transactions from Etherscan like this:
https://api.etherscan.io/api?module=account&action=txlist&address=${address}&page=1&offset=${count}&startBlock=${startBlock}&endblock=${endBlock}&sort=asc&apikey=${apiKey}
This gives me transactions that have a hex encoded input
field. Using ethers.js (ideally) how do I parse this?
What I'm trying to do is to determine the method that's shown on Etherscan, e.g. https://etherscan.io/token/0x111111111117dc0aa78b770fa6a738034120c302 (claim, transfer etc). And just inspecting the data in general. I tried:
const provider = new ethers.providers.JsonRpcProvider(
"https://mainnet.infura.io/v3/..."
)
async function fetchInterface() {
const contractAddress = "..."
const contract = new ethers.Contract(contractAddress, [], provider)
const interf = await contract.interface
// console.log(interf)
return interf
}
const logTxInput = (tx: Tx, interf: Interface) => {
const input = tx.input
console.log("!! tx input: ", input)
// error: no matching function
const parsedTx = interf.parseTransaction({ data: tx.input, value: tx.value })
// error: no matching function
const decodedArgs = interf.decodeFunctionData(input.slice(0, 10), input)
}
ethers.js version: `5.7.0`