Structs

Reading structs

The solidity storage layout documentation (opens in a new tab) outlines that "The elements of structs and arrays are stored after each other, just as if they were given as individual values."

Contract definition

Example.sol
    contract X {
        struct Item {
            uint256 index;
            string name;
        }
        Item root;   
            
        constructor() {
            root.index = 0;
            root.name = "root";
        }
    }

Reading values

Can have the name value of its constructed struct accessed as follows:

example.js
 
    const OUTPUT_COUNT = 1;
    const CONTRACT_ADDRESS = "0x123..;
 
    new GatewayRequest(OUTPUT_COUNT)        //Specify the number of outputs
      .setTarget(CONTRACT_ADDRESS)      //Specify the contract address
      .setSlot(0)                       //Specify the slot number
      .push(1)                          //Push the value 1 onto the stack
      .addSlot()                        //Increment the slot ID (by popping 1 from the stack)
      .readBytes()                      //Read the bytes
      .setOutput(0);                    //Set it at output index 0