I use web3js and createAlchemyWeb3 library.
I receive a transaction event in my log of my Ethereum transaction.
id: 334
jsonrpc: "2.0"
result: {blockHash: "0xe746216f8f73ddd67121bd7a24074e4f56a2bdc5cbe7f783d2673fafd6e992c3",…}
blockHash: "0xe746216f8f73ddd67121bd7a24074e4f56a2bdc5cbe7f783d2673fafd6e992c3"
blockNumber: "0xa7ba59"
contractAddress: null
cumulativeGasUsed: "0x87816d"
effectiveGasPrice: "0x59682f09"
from: "0x72c48277c6d1baae9696e0737b397d2ba2b48953"
gasUsed: "0x1acb3"
logs: {[
address: "0x002cc07e2a89a7a5807a63fd347fb704b8affb36"
blockHash: "0xe746216f8f73ddd67121bd7a24074e4f56a2bdc5cbe7f783d2673fafd6e992c3"
blockNumber: "0xa7ba59"
data: "0x0000000000000000000000000000000000000000000000000000000000000008"
logIndex: "0x14"
removed: false
topics: ["0xba02600589e62fdb032edca9214113caeb9517687e7ff5135693b6740e703a13"]
transactionHash: "0x4928abcc96599d2e4b39e992f26437e3f35d9572e49823847bac61ef7e442dcf"
transactionIndex: "0xd"
}]
logsBloom: "0x00000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000008000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000"
status: "0x1"
to: "0x002cc07e2a89a7a5807a63fd347fb704b8affb36"
transactionHash: "0x4928abcc96599d2e4b39e992f26437e3f35d9572e49823847bac61ef7e442dcf"
transactionIndex: "0xd"
type: "0x2"
receipt.logs[0].data = "0x0000000000000000000000000000000000000000000000000000000000000008"
it is {type:event, name:'SignId'} in my solidity
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint256",
"name": "sign_id",
"type": "uint256"
}
],
"name": "SignId",
"type": "event"
},
I use web3.eth.abi.decodeParameters like below code. but it does not working. The code stop after compile web3.eth.abi.decodeParameters
const getEthReceipt = async (txHash) => {
let res;
const types = [{ type: 'event', name: 'SignId'}];
do {
const transaction = await web3.eth.getTransactionReceipt(txHash);
let decodeParam;
if (transaction) {
decodeParam = await web3.eth.abi.decodeParameters(types, transaction.logs[0].data);
res = parseInt(transaction?.logs[0]?.data).toString(10);
console.log(decodeParam); // not working
// await chainMintRequest("eth", decodeParam);
}
} while (!res);
};
I reffered
how to decode log event of my transaction log? https://github.com/ChainSafe/web3.js/issues/2848
I update code
const getEthReceipt = async txHash => {
// console.log(txHash);
let res;
const types = ["uint256"];
do {
console.log(1);
const transaction = await web3.eth.getTransactionReceipt(txHash);
let decodeParam;
if (transaction) {
console.log(transaction);
decodeParam = await web3.eth.abi.decodeParameter(types, transaction.logs[0].topics[0]);
console.log(decodeParam);
res = parseInt(transaction?.logs[0]?.data).toString(10);
console.log(res);
// await chainMintRequest("eth", decodeParam);
}
} while (!res);
};
console.log(decodeParam) and console.log(res) doesn't appear on my console.
The code did not work after web3.eth.abi.decodeParameter and there is no error
types
parameters seems to be wrong, it is expecting an array of basic data types. Try withtypes = ['uint256'];
web3 = new Web3(...);