How do you pass an array of structs from Truffle (javascript) to a smart contract (Solidity)?
There are a few similar questions (like this one and this one) whose answers say you cannot pass a struct to a public function in solidity or are using a version of Solidity before 4.0.19. However, I'm using ABIEncoderV2, where this is not a problem.
I'm getting the following error:
Error: invalid solidity type!: tuple[]
Truffle test suite:
const foo = artifacts.require('./FOO.sol');
it('test', async () => {
let coordsContract = await foo.new();
const coord0 = {x: 100, y: 200};
const coords = [coord0];
const worked = await coordsContract.loopCoords(coords);
assert.isTrue(worked);
});
Solidity contract:
pragma solidity ^0.4.23;
pragma experimental ABIEncoderV2;
contract FOO {
struct Coordinates {
uint256 x;
uint256 y;
}
function loopCoords(Coordinates[] coords) public returns (bool) {
for (uint i = 0; i < coords.length; i++) {
//do stuff
}
return true;
}
}