-
Ethers Version6.3.0 Search Termsevent log Describe the ProblemThere is an exception parsing some (not all) erc20 event logs from Polygon. This happens on both Infura and polygon-rpc.com endpoints. Code Snippetimport { ethers } from 'ethers'
import ierc20Abi from '@openzeppelin/contracts/build/contracts/IERC20.json'
let ierc20 = new ethers.Interface(ierc20Abi.abi)
async function main() {
let provider = new ethers.JsonRpcProvider('https://polygon-rpc.com')
let blockNum = 42689001
let logs = await provider.getLogs({fromBlock: blockNum, toBlock: blockNum})
let events = logs.map((log) => {
try {
return ierc20.parseLog({ data: log.data, topics: log.topics.slice() })
} catch (e) {
console.error("failed parsing log", e, log)
}
}).filter((l) => !!l)
}
main() Contract ABI{
"_format": "hh-sol-artifact-1",
"contractName": "IERC20",
"sourceName": "contracts/token/ERC20/IERC20.sol",
"abi": [
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "spender",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "Approval",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "from",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "to",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "Transfer",
"type": "event"
},
{
"inputs": [
{
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"internalType": "address",
"name": "spender",
"type": "address"
}
],
"name": "allowance",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "spender",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "approve",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "account",
"type": "address"
}
],
"name": "balanceOf",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "totalSupply",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "to",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "transfer",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "from",
"type": "address"
},
{
"internalType": "address",
"name": "to",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "transferFrom",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
}
],
"bytecode": "0x",
"deployedBytecode": "0x",
"linkReferences": {},
"deployedLinkReferences": {}
} Errorsfailed parsing log RangeError: data out-of-bounds (buffer=0x, length=0, offset=32, code=BUFFER_OVERRUN, version=6.3.0)
at makeError (/node_modules/ethers/src.ts/utils/errors.ts:660:21)
at assert (/node_modules/ethers/src.ts/utils/errors.ts:680:25)
at Reader.#peekBytes (/node_modules/ethers/src.ts/abi/coders/abstract-coder.ts:419:23)
at Reader.readBytes (/node_modules/ethers/src.ts/abi/coders/abstract-coder.ts:436:36)
at Reader.readValue (/node_modules/ethers/src.ts/abi/coders/abstract-coder.ts:444:30)
at NumberCoder.decode (/node_modules/ethers/src.ts/abi/coders/number.ts:54:33)
at /node_modules/ethers/src.ts/abi/coders/array.ts:108:31
at Array.forEach (<anonymous>)
at unpack (/node_modules/ethers/src.ts/abi/coders/array.ts:86:12)
at TupleCoder.decode (/node_modules/ethers/src.ts/abi/coders/tuple.ts:66:22) {
code: 'BUFFER_OVERRUN',
buffer: Uint8Array(0) [],
length: 0,
offset: 32
} Log {
provider: JsonRpcProvider {},
transactionHash: '0x3c2a0bfbf1ab5b345151da7afbc8d6a2751cf9db91585cebd282d7f05d966fad',
blockHash: '0x850c5758aba451a963ff2510f133aec6e037a6f4b13afb9c9798147ce54c93fc',
blockNumber: 42689001,
removed: false,
address: '0x5e6589b5C06096405BDBCe59821027C6854b1A44',
data: '0x',
topics: [
'0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
'0x0000000000000000000000000000000000000000000000000000000000000000',
'0x000000000000000000000000679a80fcee8f469f7e194433066d72db03d2f457',
'0x000000000000000000000000000000000000000000000000000000000002e55a'
],
index: 340,
transactionIndex: 49
} EnvironmentAltcoin - Please specify (e.g. Polygon) Environment (Other)Polygon |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
This also happens with ethers js 5.7.2. Node version 18.12.0. Edit: It appears that the empty log data is the issue; my guess is that it's a token transfer with 0 value? Polygonscan sees the same thing here. There are also some events with no topics at all, which result in an error when calling |
Beta Was this translation helpful? Give feedback.
-
One more thing, there's a type error passing a log from |
Beta Was this translation helpful? Give feedback.
-
The log is incorrect for the ABI. The abi indicates My guess is you are using the ERC-20 ABI for an ERC-721 contract. Try updating the ABI to use ERC-721 and this log should parse fine. :) |
Beta Was this translation helpful? Give feedback.
The log is incorrect for the ABI. The abi indicates
Transfer(address indexed, address indexed, uint)
but the log is forTransfer(address indexed, address indexed, uint indexed)
.My guess is you are using the ERC-20 ABI for an ERC-721 contract.
Try updating the ABI to use ERC-721 and this log should parse fine. :)