I am kinda new to solidity and I have this error that keeps popping up after I deployed the contract and run the initTest() function. What I am trying to do is passing the string that I insert in the initTest() on the runTest so it runs and save the entire string on the blockchain. I don't have any error when I compile the contrct, only after I deployed it.

pragma solidity ^0.8.0;
import "../contracts/Code.sol";

contract CodeTest {

    ContrIdCard private _UniCode;
    bytes[] private CustID;      
    bytes[] private ContractID ;
   function pubblishCode (bytes memory _CustID, bytes memory _ContractID, bool _MultiCustID) private {
       _UniCode.mkCode(_CustID, _ContractID, _MultiCustID);

   function initTest() public {
      uint i = 0;
      CustID[i] = "04wT9Os3uv7p"; ContractID[i++] = "e7tk6peihfcc6ece1ffbe8f8cd433ae61c1081ae6b94";
   function runTest(bool _MultiCustID) public {
        for (uint i = 0; i<CustID.length; i++)
            pubblishCode (CustID[i], ContractID[i], _MultiCustID); 
   function runTest() public {

The error given when I run initTest() is: "transact to CodeTest.initTest errored: VM error: revert.

revert The transaction has been reverted to the initial state. Note: The called function should be payable if you send value and the value you send should be less than your current balance. Debug the transaction to get more information."

When I do the debug it gives me value 0 for the CustID e ContractID. What can I do to fix it?

1 Answer 1


There are some problems with the function initTest:

  1. Your index variable i is declared inside the function so the counter is not persistent so you won't have your planned logic as it always equals to 0 when a function is called.
  2. You cannot assign new values to elements of an array that do not exist yet. Use .push(value) to append to an array.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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