0

Very beginner question! I am having a really tough time initializing an array of uints. I have a test contract that consists of 1 line to test this and though it compiles, when I view the data in the public variable it throws a bigNumber error that I am not familiar with.

pragma solidity ^0.8.0;

contract Test {
    uint[2] public numberArray = [125,546];
}

This results in the following error when called: enter image description here

I receive the same error when I try and append to an empty array. I'm not sure how to add uints to an array. The contract was deployed to a JS VM if that matters.

I think it has to be something local because I have pasted in other's work and got the same error.

1
  • Can you share how you try to access numberArray ? Nov 24 at 9:48
0

Try passing a parameter to the function call, like 0 to get the first element. It looks like you're trying to get the whole array using the default getter but that's not possible, you need to supply the index to return, or create a separate function that will return the whole array.

1
  • 1
    Thank you so much that's it! Dec 1 at 23:45

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.