1

I have a smart contract that is exposing a list of addresses:

contract AddressBook {

    uint public val = 1000;
    address[] public addresses;

}

Then I do truffle compile && truffle migrate --reset After that, I run truffle console.

In the console, I bind the contract to a variable:

AddressBook.deployed().then(function(i){ab=i})

Now when I run:

ab.val.call()

It gives me back the proper result.

But when I run:

ab.addresses.call()

It responds with:

Error: Invalid number of arguments to Solidity function

I don't know why. Please help.

1

Actually the addresses variable is an array, so when you make a call use an element index number to access it.

AddressBook.deployed().then(function(i){i.addresses(indexNumer)})

or

ab.addresses(indexNumber)
  • It gives an error: Error: Error: VM Exception while executing eth_call: invalid opcode – Marko Jakovic Oct 23 '17 at 12:12
  • Please check updated answer – Afzaal Ahmad Oct 23 '17 at 16:48
  • I am still getting the same error. – Marko Jakovic Oct 23 '17 at 17:52
  • which client are you using – Afzaal Ahmad Oct 23 '17 at 18:18
  • Truffle v3.4.11 (core: 3.4.11) Solidity v0.4.15 (solc-js) TestRPC v4.1.3 (ganache-core: 1.1.3) – Marko Jakovic Oct 24 '17 at 9:25
0

Try deleting the build folder and run

truffle migrate --reset --compile-all

I had the same issue, the compiled code is corrupted. It works for the first time only and the subsequent compile corrupts the build. Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.