Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

353
Views
Passing array to smart contract from web3

I'm having a problem passing an array from web3 to smart contract. I have an array declared as names=[] with data parsed as int;

I am planning to send a value to my smart contract with the function:

function vote(uint[] memory candID,uint id,uint elid) public {
   //code here
  }

using this code in my frontend:

await contract.methods.vote([names],BigInt(election),BigInt(electClickedID)).send({ from: accounts[0], gas: 3000000 });

I always face an error, but when passing data manually, like :

await contract.methods.vote([0,1,5],BigInt(election),BigInt(electClickedID)).send({ from: accounts[0], gas: 3000000 });

it succeeds.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Your variable names is an empty 1-dimensional array, By wrapping it in the additional [] expression, you're effectively passing a 2-dimensional array to the Solidity function.

For example, if the value of names was [0,1,5], you'd be passing [[0,1,5]] - an array of one item, which [the item] is another array of three items.

Which is not valid, as the Solidity function accepts a 1D array.

Solution: Remove the array wrapper.

let names = [];

await contract.methods.vote(
    names, // instead of `[names]`
    BigInt(election),
    BigInt(electClickedID)
).send({
    from: accounts[0],
    gas: 3000000
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!