Decode transaction input params #845
-
I'm trying to decode the transaction's input data to further display it with React. The transaction is OpenZeppelin ERC20's I need it to display the amount of transferred tokens when the transaction is finished. I cannot get this from state because of some requirements for specific reasons. My current code results in an error:
const {data : transactionData, isLoading : isTransactionDataLoading } = useWaitForTransaction({
hash: transactionHash ? transactionHash : _transactionHash,
onSuccess: () => {
},
enabled: !!(transactionHash || _transactionHash)
});
From the console I can see that the transactionData is valid and the status is success. Data size of 32 bytes is too small for given parameters. Params: (address to, uint256 amount) Which property of the Please advice! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
OK, figured it out :) For the recepient ("to") I had to reference decodeAbiParameters([{
type: 'uint256',
name: 'amount'
}], transactionData.logs[0].topics[2])) and for "amount" decodeAbiParameters([{
type: 'uint256',
name: 'amount'
}], transactionData.logs[0].data) Hope it helps someone else! |
Beta Was this translation helpful? Give feedback.
-
This is the best way that I found to decode the transaction import { decodeFunctionData } from "viem"
const transaction = await client.getTransaction({
hash: transactionHash,
})
const { args } = decodeFunctionData({
abi: erc20ABI,
data: transaction.input,
})
console.log(args) |
Beta Was this translation helpful? Give feedback.
OK, figured it out :)
For the recepient ("to") I had to reference
and for "amount"
Hope it helps someone else!