-
Ethers Version5.6.9 Search Termsinterface, parseLog Describe the ProblemAm getting logs from the blockchain by making RPC call to my private node using With some logs everything works fine but at some other logs I get data out-of-bound error. I have looked through other similar issues non seems to fix the error or maybe there is something am still missing. Am only interested in decoding ERC721 compliant tokens Code Snippetconst logs = [
{
address: '0x3a7711989386601293d1fc1bd09e1eeed24d3d1e',
topics: [
'0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
'0x0000000000000000000000000000000000000000000000000000000000000000',
'0x0000000000000000000000007e31af176da39a9986c8f5c7632178b4acf0c868',
],
data: '0x00000000000000000000000000000000000000000003d8ad014e6c1dc6400000',
blockNumber: 9212671,
transactionHash:
'0xc270bf62d267a7fe8a70415b4590ba1e987a428bf6d85672415283f600f4cb7a',
transactionIndex: 0,
blockHash:
'0x8ad2e0586d7f55b4655217c0f33890888e48adf1cd5112a2621457dc6935a72d',
logIndex: 1,
removed: false,
}
]
const iface = new utils.Interface(ERC721Abi);
const events = logs.map((log) => {
return {
contractAddress: log.address,
args: iface.parseLog(log)
}
})
console.log(JSON.stringify(events)) Contract ABI[{
"anonymous": false,
"inputs": [{
"indexed": true,
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "approved",
"type": "address"
},
{
"indexed": true,
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
}
],
"name": "Approval",
"type": "event"
},
{
"anonymous": false,
"inputs": [{
"indexed": true,
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "operator",
"type": "address"
},
{
"indexed": false,
"internalType": "bool",
"name": "approved",
"type": "bool"
}
],
"name": "ApprovalForAll",
"type": "event"
},
{
"anonymous": false,
"inputs": [{
"indexed": true,
"internalType": "address",
"name": "from",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "to",
"type": "address"
},
{
"indexed": true,
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
}
],
"name": "Transfer",
"type": "event"
},
{
"inputs": [{
"internalType": "address",
"name": "to",
"type": "address"
},
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
}
],
"name": "approve",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [{
"internalType": "address",
"name": "owner",
"type": "address"
}],
"name": "balanceOf",
"outputs": [{
"internalType": "uint256",
"name": "balance",
"type": "uint256"
}],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
}],
"name": "getApproved",
"outputs": [{
"internalType": "address",
"name": "operator",
"type": "address"
}],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"internalType": "address",
"name": "operator",
"type": "address"
}
],
"name": "isApprovedForAll",
"outputs": [{
"internalType": "bool",
"name": "",
"type": "bool"
}],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "name",
"outputs": [{
"internalType": "string",
"name": "",
"type": "string"
}],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
}],
"name": "ownerOf",
"outputs": [{
"internalType": "address",
"name": "owner",
"type": "address"
}],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{
"internalType": "address",
"name": "from",
"type": "address"
},
{
"internalType": "address",
"name": "to",
"type": "address"
},
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
}
],
"name": "safeTransferFrom",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [{
"internalType": "address",
"name": "from",
"type": "address"
},
{
"internalType": "address",
"name": "to",
"type": "address"
},
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
},
{
"internalType": "bytes",
"name": "data",
"type": "bytes"
}
],
"name": "safeTransferFrom",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [{
"internalType": "address",
"name": "operator",
"type": "address"
},
{
"internalType": "bool",
"name": "_approved",
"type": "bool"
}
],
"name": "setApprovalForAll",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [{
"internalType": "bytes4",
"name": "interfaceId",
"type": "bytes4"
}],
"name": "supportsInterface",
"outputs": [{
"internalType": "bool",
"name": "",
"type": "bool"
}],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "symbol",
"outputs": [{
"internalType": "string",
"name": "",
"type": "string"
}],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
}],
"name": "tokenURI",
"outputs": [{
"internalType": "string",
"name": "",
"type": "string"
}],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{
"internalType": "address",
"name": "from",
"type": "address"
},
{
"internalType": "address",
"name": "to",
"type": "address"
},
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
}
],
"name": "transferFrom",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
] Errorsconst error: any = new Error(message); ^
Error: data out-of-bounds (length=64, offset=96, code=BUFFER_OVERRUN, version=abi/5.6.4) Environmentnode.js (v12 or newer) Environment (Other)No response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Unfortunately, because Solidity does not include the indexed keyword when computing topic hashes, the ERC-20 and ERC-721 Transfer events share the identical topic hash. As a result, a filter for one will also get the other, and they are incompatible (as ERC-721 indexes the tokenId and ERC-20 does not index the equivalent field amount). If you have a contract that emits both, you will need to further refine by some other method, such as by topic length or the presence of data. You can also trap errors and possibly discard them, depending on your use case. Does that make sense? It would have been nice if ERC-721 also didn’t try to be compatible with ERC-20. :s |
Beta Was this translation helpful? Give feedback.
Unfortunately, because Solidity does not include the indexed keyword when computing topic hashes, the ERC-20 and ERC-721 Transfer events share the identical topic hash.
As a result, a filter for one will also get the other, and they are incompatible (as ERC-721 indexes the tokenId and ERC-20 does not index the equivalent field amount).
If you have a contract that emits both, you will need to further refine by some other method, such as by topic length or the presence of data. You can also trap errors and possibly discard them, depending on your use case.
Does that make sense? It would have been nice if ERC-721 also didn’t try to be compatible with ERC-20. :s