I'm trying to define contract ABI (part of standard ERC-721) as follows:
export const ERC721_STANDARD_ABI = [
"function balanceOf(address owner) view returns (uint)",
"function transfer(address to, uint amount)",
"event Transfer(address indexed from, address indexed to, uint amount)",
"function tokensOfOwner(address _owner) external view returns (uint[] memory)",
"function tokenURI(uint256 tokenId) public view returns (string memory)",
];
Then, I initialize my contract:
const contract = new ethers.Contract(address!, ERC721_STANDARD_ABI, provider);
(where my address is a valid ERC-721 contract address and provider is Alchemy provider with my API key).
I prepare my filter as follows: const filter = contract?.filters!.Transfer()!;
which is valid and parsed as seen in debugger (it correctly identifies this as an event with 3 arguments, which implies that it is parsed correctly from the human-readable ABI):
Then I try to query with the filter:
await contract!.queryFilter(filter)
Which results in the following error:
RangeError: data out-of-bounds (buffer=0x, length=0, offset=32, code=BUFFER_OVERRUN, version=6.0.5)
at makeError ([redacted]/node_modules/ethers/src.ts/utils/errors.ts:660:21)
at assert ([redacted]/node_modules/ethers/src.ts/utils/errors.ts:680:25)
at Reader.#peekBytes ([redacted]/node_modules/ethers/src.ts/abi/coders/abstract-coder.ts:419:23)
at Reader.readBytes ([redacted]/node_modules/ethers/src.ts/abi/coders/abstract-coder.ts:436:36)
at Reader.readValue ([redacted]/node_modules/ethers/src.ts/abi/coders/abstract-coder.ts:444:30)
at NumberCoder.decode ([redacted]/node_modules/ethers/src.ts/abi/coders/number.ts:54:33)
at [redacted]/node_modules/ethers/src.ts/abi/coders/array.ts:108:31
at Array.forEach (<anonymous>)
at unpack ([redacted]/node_modules/ethers/src.ts/abi/coders/array.ts:86:12)
at TupleCoder.decode ([redacted]/node_modules/ethers/src.ts/abi/coders/tuple.ts:66:22)
What am I doing wrong?
I just used query events the way you did and I successfully filtered
const filters = contract.filters.NftItemCreated();
console.log("transfer event filters", filters);
const filterResult = await contract.queryFilter(filters);
console.log("filterResult", filterResult);
here is the result:
I try to check "node_modules/ethers/src.ts" directory that logged in the error message, "src.ts" exists but it does not include files mentioned in the error message. That makes me think that the problem is with the package version. I tested the code with this version
"ethers": "^5.6.4",
Since you have this const filter = contract?.filters!.Transfer()!
, looks like you constructed the contract properly. Usually "data out-of-bounds" when you pass the wrong arguments to construct the contract, for example, your abi file is corrupted.
The RangeError object indicates an error when a value is not in the set or range of allowed values.