-
Ethers Version6.6.2 Search Termsabi types parameter Describe the ProblemIn v5 it was possible to just load an abi definition, and forward all parameters (potentially coming from an api request) to the contract "populate" method. In v6 this is not possible anymore since it does not accept the empty array [ ] for the type "bytes". Unfortunately:
--> It would be great, if an untyped array is also accepted and tried to be treated and parsed like an UInt8Array with the from() or of() method. Otherwise it is not possible without further intervention to provide parameters via json / rest apis directly, without messing with the abi and checking datatypes outside ethers-lib. Code Snippetasync function main() {
const abi = `[
{
"inputs": [
{
"internalType": "address",
"name": "to",
"type": "address"
},
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
},
{
"internalType": "bytes",
"name": "data",
"type": "bytes"
}
],
"name": "mint",
"outputs": [],
"stateMutability": "payable",
"type": "function"
}
]`
const abiInterface = new Interface(abi)
const provider = new JsonRpcProvider(
"http://......",
{
name: "MyNetwork",
chainId: 80001,
}, {
staticNetwork: Network.from({
name: "MyNetwork",
chainId: 80001,
})
}
)
const contractAddress: string = "0x1234567"
const contract = new Contract(contractAddress, abiInterface, provider)
const contractFunction = contract["mint"]
const paramsFromJson = [
"0x0f08462efc7f2f0e0a3e773ca95e2aadee584baf",
1,
1,
[]] // What to put here now in v6?
const transaction = await contractFunction.populateTransaction(...paramsFromJson)
} Contract ABI[
{
"inputs": [
{
"internalType": "address",
"name": "to",
"type": "address"
},
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
},
{
"internalType": "bytes",
"name": "data",
"type": "bytes"
}
],
"name": "mint",
"outputs": [],
"stateMutability": "payable",
"type": "function"
}
] ErrorsTypeError: invalid BytesLike value (argument="value", value=[ ], code=INVALID_ARGUMENT, version=6.6.2) Environmentnode.js (v12 or newer) Environment (Other)No response |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
You should be able to pass in |
Beta Was this translation helpful? Give feedback.
-
Hi, indeed that worked. So that seems only array notation is not supported anymore? |
Beta Was this translation helpful? Give feedback.
-
Yes, array of numbers is no longer supported, as they require a lot more validation and were kinda a nuisance to deal with when trying to deduce types (is it an array of numbers? Is it a tuple of things?). You can still use them though, by passing them into Uint8Array, like Make sense? (Moving to discussions ;)) |
Beta Was this translation helpful? Give feedback.
-
Hi. Yes, totally makes sense, for me this behavior is ok and no more need for discussion... Thanks! :) |
Beta Was this translation helpful? Give feedback.
Yes, array of numbers is no longer supported, as they require a lot more validation and were kinda a nuisance to deal with when trying to deduce types (is it an array of numbers? Is it a tuple of things?).
You can still use them though, by passing them into Uint8Array, like
new Uint8Array([ 1, 2, 3 ])
, but that doesn’t help your situation with JSON.Make sense? (Moving to discussions ;))