Description
Ethers Version
6.7.1
Search Terms
elementary, invalid param type
Describe the Problem
function
is an elementary Solidity type which is ABI-encoded the same as bytes24. It consists of an address (20 bytes) followed by a function selector (4 bytes). Documentation ref: https://docs.soliditylang.org/en/latest/abi-spec.html#types
It seems like ethers' ABI coder has never had support for this type, so errors are thrown when trying to decode an ABI containing a function type. What's funny is the function type was added to Solidity almost 7 years ago, but I guess it hasn't been popular enough for anyone to notice: ethereum/solidity#1122
Example contract (see getFunction
function):
(Otterscan) https://sepolia.otterscan.io/address/0xb0e9daBA710617b2C398b3987716B2F1f36bB228/contract (select Sourcify Servers data source from hamburger in upper right)
(Etherscan) https://sepolia.etherscan.io/address/0xb0e9daBA710617b2C398b3987716B2F1f36bB228#code
Code Snippet
ethers.ParamType.from("function")
Contract ABI
[{"inputs":[{"internalType":"function () external","name":"val","type":"function"}],"name":"getFunction","outputs":[{"internalType":"function () external","name":"","type":"function"}],"stateMutability":"pure","type":"function"}]
Errors
TypeError: invalid param type (argument="obj", value="function", code=INVALID_ARGUMENT, version=6.7.1)
at makeError (node_modules/ethers/lib.commonjs/utils/errors.js:118:21)
at assert (node_modules/ethers/lib.commonjs/utils/errors.js:142:15)
at assertArgument (node_modules/ethers/lib.commonjs/utils/errors.js:154:5)
at ParamType.from (node_modules/ethers/lib.commonjs/abi/fragments.js:625:47) {
code: 'INVALID_ARGUMENT',
argument: 'obj',
value: 'function'
}
Environment
node.js (v12 or newer)
Environment (Other)
No response