Nested array support
See original GitHub issueHello -
Came here thanks to the helpful link at ethereum/web3.js#1137.
I was trying out the new experimental support for nested dynamical array in ABIEncoderV2
.
Turns out there is currently no ABI decoder that supports it if I am not wrong.
Just wanted to open a ticket to make sure that this is also same with ethers.js.
Here is a quick test case I got:
Registry.sol
pragma solidity ^0.4.18;
pragma experimental SMTChecker;
pragma experimental ABIEncoderV2;
contract Registry {
bool[][] matrix;
function Registry() {
bool[] memory test = new bool[](2);
test[0] = true;
test[1] = true;
matrix.push(test);
}
function adjacency_matrix() constant returns (bool[][]) {
return matrix;
}
function getLength() constant returns (uint length) {
length = matrix.length;
}
}
ethers-js.ts
import {Wallet, Contract, providers} from "ethers";
const wallet = new Wallet("0x8e6e5c8c3239e87ab550aa58d797c2c71355a1e4e2ef2342884a3462548b82d6", new providers.JsonRpcProvider(undefined, "development"));
const abi = [
{
"constant": true,
"inputs": [],
"name": "getLength",
"outputs": [
{
"name": "length",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "adjacency_matrix",
"outputs": [
{
"name": "",
"type": "bool[][]"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
}
];
const contract = new Contract("0x80446d11f150c883ab148b5c4014c3e859ff1662", abi, wallet);
const result = contract.adjacency_matrix();
result.then((res) => {console.log(res)}).catch((e) => {console.log(e)});
Result:
$ ts-node ethers-js.ts
{ Error: invalid type
at throwError (/home/isaac/Development/truffle/node_modules/ethers-utils/throw-error.js:4:17)
at getParamCoder (/home/isaac/Development/truffle/node_modules/ethers-contracts/interface.js:290:48)
at /home/isaac/Development/truffle/node_modules/ethers-contracts/interface.js:587:21
at Array.forEach (<anonymous>)
at Function.decodeParams (/home/isaac/Development/truffle/node_modules/ethers-contracts/interface.js:586:11)
at CallDescription.result.parse (/home/isaac/Development/truffle/node_modules/ethers-contracts/interface.js:406:50)
at /home/isaac/Development/truffle/node_modules/ethers-contracts/contract.js:115:37
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:228:7) type: '' }
Will update this issue with further details. I will be looking into (1) creating a test case for this or even (2) contributing.
Thanks -Isaac
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:8 (7 by maintainers)
Top Results From Across the Web
Understanding Nested Arrays in JavaScript | by Sanchitha SR
JavaScript lets us create arrays inside array called Nested Arrays. Nested Arrays have one or many arrays as the element of an array....
Read more >Understanding Nested Arrays in JavaScript
JavaScript lets us create arrays inside array called Nested Arrays. Nested Arrays have one or many arrays as the element of an array....
Read more >Array.prototype.flat() - JavaScript - MDN Web Docs
The flat() method creates a new array with all sub-array elements ... The depth level specifying how deep a nested array structure should...
Read more >Example: Nested Arrays - PTC Support
In this example, the display of nested arrays is in a collapsed format. The nested array elements are not visible and only the...
Read more >#CALC! error - Nested array - Microsoft Support
The nested array error occurs when you try to input an array formula that ... To resolve the error, try removing the second...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
Top Related Tweet
No results found
Top Related Dev.to Post
Top Related Hashnode Post
No results found
Top GitHub Comments
This is now supported in the
encodeParams
anddecodeParams
methods of Interface. I will soon get JSON support for naming the nested objects nicely. But for now you can do:There are just over 2000 test cases compiled against a local PoA parity node located in
tests/tests/contract-interface-abi2.json.gz
that all pass. A small bug has been found in the v2 Solidity compiler (this is an experimental feature after all), and I’ve opened an issue, and they are looking into it. Once that is fixed there are a few more test cases that will be added to this coder.Full support for decoding is now available. Encoding works for arrays, but not named items yet.