0
votes

I'm trying to pass a string[] from node.js to solidity function:

function test(string[] memory options) public {}

like this way:

const options = ["a","b","c"]
const contract = this.getContract();
const testFunc = contract.functions['test'];
await testFunc(options);

but got the error: invalid value for array;

Solidity pragma:

pragma solidity 0.6.5; pragma experimental ABIEncoderV2;

Also, if I call a contract from Etherscan with the same value it works

1

1 Answers

0
votes

contract.functions is used in ethers.js (docs). Since your question is tagged web3, my answer is using the web3 library.

Assuming that this.getContract() returns the Contract instance, you can execute a contract method using the contract.methods (docs) object.

Use .send() to send a read-write transaction from your configured wallet, or .call() to make a read-only call.

const options = ["a","b","c"]
const contract = this.getContract();
await contract.methods.test(options).send();