[Ethereum] How to pass an array as the function parameter

contract-developmentdapp-developmentdappssolidityweb3js

I meet the same problem as this question:
Passing an array as a parameter from javascrpt (web3) to a Solidity function

If I call my function in the browser-solidity with the parameter [122,44], it works well.
But if I use it in my own web UI, it throw out "Error: new BigNumber() not a number".
The way I call it is like:

myContract.myFunction([122,44],{from:accounts[0]},function(err,res){...})

or

myContract.myFunction(["122","44"],{from:accounts[0]},function(err,res){...})

I don't know why. It should be the same result as in the browser-solidiy.

Best Answer

What types your solidity function expects? If it's uint or int then you must convert your params to BigNumber before you passing it. E.g.:

import BigNumber from 'bignumber.js';
let myParams = [122,44];
let convertedParams = myParams.map( item => { return new BigNumber(item)});
myContract.myFunction(convertedParams,{from:accounts[0]},function(err,res){...})
Related Topic