ethers.js
ethers.js copied to clipboard
encodeFilterTopics does not support negative values
Ethers Version
6.8.1
Search Terms
abi, topics, int256
Describe the Problem
I added a Test interface with int256
indexed topic as follow:
function encodeTopics(name, value) {
var iface = new ethers.Interface([
"event Test(int256 indexed test)"
]);
var filter = iface.encodeFilterTopics("Test", [ value ]);
return filter[1];
}
and run it with encodeTopics("-1")
, I got this:
RangeError: unsigned value cannot be negative (fault="overflow", operation="getUint", value="-1", code=NUMERIC_FAULT, version=6.8.1)
This should be able to take negative integers, but toBeHex
and getUint
function does not allow negative values here. I was expecting -1
to be encoded successfully to (ffffffffff...ffff
)
Code Snippet
function encodeTopics(value) {
var iface = new utils.Interface([
"event Test(int256 indexed test)"
]);
var filter = iface.encodeFilterTopics("Test", [ value ]);
return filter[1];
}
encodeTopics("-1")
### Contract ABI
_No response_
### Errors
```shell
RangeError: unsigned value cannot be negative (fault="overflow", operation="getUint", value="-1", code=NUMERIC_FAULT, version=6.8.1)
Environment
No response
Environment (Other)
No response