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

97
Views
Error invalid opcode trying to access Solidity array of structs in Hardhat

I have the following struct and array in my Solidity code:

    struct Character {
        int256 strength;
        uint256 dexterity;
        uint256 constitution;
       ....
    }

    Character[] public characters;

I have the following line in my Hardhat test attempting to access a member of that array:

const character = await contract.characters(0)

I then get the following error:

 Error: VM Exception while processing transaction: invalid opcode
      at Contract.characters 

What is the correct way to access a member of this array of structs?

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

0

As pointed out in the question comment, the characters array was empty when the characters(0) function was called.

Solidity autogenerates getter functions for public arrays, allowing to access an item of the array using its index.

When you try to access an index that is out of bounds, the EVM throws an exception.

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!