question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Call contract methods with "dynamic-length arrays" arguments

See original GitHub issue

Hi,

Could you please let me know how I can call contract methods with “dynamic-length arrays” arguments. I have read this document: Write Methods, and it is quite brief. Codility function example: function paySalary(address[] employeeList) public payable {}

In Javascript, I have tried many things including passing an array: let emplyeeList = [addr_John, addr_Mark, addr_Steve]; await myDapp.paySalary(emplyeeList, overrides); But it seems it does not work. In the smart contractpaySalary(address[] employeeList), it only takes the first element(length is 1). Could you please share some insights. Thanks for your great help.

B.R Andy

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
zemsecommented, Oct 30, 2020

The way you are trying looks completely fine and I use it al the time.

  1. Can you console.log(emplyeeList) to see if there are three addresses present or are last two undefined.
  2. Is possible that you can use latest versions of Solidity (v0.7) and ethers js (v5)? I can confirm that the way your using works fine in latest versions, maybe some bugs in older versions which may got fixed.
  3. If you really need to stick to those versions, can you list the versions you are using.
1reaction
AndyJiangProcommented, Nov 24, 2020

Hi, @ricmoo yes, it does work. I forgot to reply, sorry. Please close it. Thanks for your help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Smart contract external function with dynamic array of bytes32 ...
I create contract with correct ABI (checked it several times), pass the same arguments to it's function contracts.startNewBallot(). Transaction ...
Read more >
Dynamic Arrays and its Operations in Solidity - GeeksforGeeks
The Dynamic arrays are the arrays that are allocated memory at the runtime and the memory is allocated from the heap. ... int[]...
Read more >
Limits of Returning Arrays of Dynamic Size in Solidity Smart ...
So, we will research the dependency between gas spent and array size in bytes. We are using uint256[] array for simplicity. For other...
Read more >
Failed to call solidity function with array argument
This solution works well, if arguments sizes are known at compile time, but with dynamic sizes this doesn't work. How can I resolve...
Read more >
Solidity Tutorial: all about Array | by Jean Cvllr - Medium
Array types · Fixed-size vs dynamic size arrays; One-dimensional vs Multi-Dimensional arrays. · Fixed Size: T[k] · Dynamic Size: T[] · T[k] :...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found