Reading value types
As outlined in the solidity storage layout documentation (opens in a new tab), "Except for dynamically-sized arrays and mappings (see below), data is stored contiguously item after item starting with the first state variable, which is stored in slot 0."
As such, for a contract defining a uint256 as follows:
Contract definition
Example.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;
contract Example {
uint256 slot0 = 123;
}We read the uint256 value in slot 0 using the following request:
Reading values
example.js
new GatewayRequest(1) //Specify the number of outputs
.setTarget(CONTRACT_ADDRESS) //Specify the contract address
.setSlot(0) //Specify the slot number
.read() //Read the value
.setOutput(0) //Set it at output index 0