y-pakorn / flutter_web3

Web3 Ethereum, Etherjs and Wallet Connect wrapper for Flutter Web.
Other
136 stars 46 forks source link

"Error: invalid value for array" when one of the input arguments is array #38

Closed dvalevv closed 2 years ago

dvalevv commented 2 years ago

The bug:

I am trying to execute read function from a contract which requires 2 argument:

  1. unit256
  2. address[] (2 addresses are required here)

However, no matter how I try to input the second argument, I am always getting - "Error: invalid value for array"

I have also found similar unresolved question on StackOverflow, where the same error is caused there because an array of unit is required as input.

Additional info:

my code:

final contractAddress = '0x60aE616a2155Ee3d9A68541Ba4544862310933d4';
const jason_abi = '{
  "type":"function"
  "name":"getAmountsOut",
  "stateMutability":"view",
  "inputs":[
      {"internalType":"uint256","name":"amountIn","type":"uint256"}, 
      {"internalType":"address[]","name":"path","type":"address[]"}
    ],
  "outputs":[
      {"internalType":"uint256[]","name":"amounts","type":"uint256[]"}
    ],
}';
const human_abi = ["function getAmountsOut(uint256 amountIn, address[] calldata path) external view returns (uint256[] memory amounts)"];

final wavax = EthUtils.getAddress("0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7");
final mim = EthUtils.getAddress("0x130966628846bfd36ff31a822705796e8cb8c18d");

final contract = Contract(contractAddress, human_abi, provider!);

await contract.call('getAmountsOut', [1, [wavax, mim]]).then((value) {
  print("unclaimed rewards - ${value.toString()}");
});  // <--- Gives me the error, maybe because this inner list is interpreted as tuple?

Ways I have tried to input before opening the issue are:

In my specific case the function is from TraderJoeRouter on Avalanche Chain. Contract of the router - "0x60aE616a2155Ee3d9A68541Ba4544862310933d4", function name - "getAmountsOut"

y-pakorn commented 2 years ago

Thanks for reporting the bug. The fix will be available on next version.

y-pakorn commented 2 years ago

Fixed in v2.1.9 and v.2.2.0-pre.7. Closing now.

dvalevv commented 2 years ago

Thanks you for the fast response!