Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

106
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda