# JSON RPC Call using ETH getStorage

1. Within the scripts folder, create a file called `getStorage.js`
2. Let's write our `getStorage.js` script

```
const hre = require("hardhat");
const { ethers } = require("ethers");

const getStorageValue = async (rpcURL, contractAddress, slotNumber) => {
  const provider = new ethers.getDefaultProvider(rpcURL); // initial ether rpc

  try {
    const storageValue = await provider.getStorage(contractAddress, slotNumber);
    console.log(`\nResponse:`);
    console.log(`Storage Value at Slot ${slotNumber}: 0x${storageValue}`);
  } catch (error) {
    console.error("Error:", error);
  }
};

async function main() {
  const contractAddress = "0xf84Df872D385997aBc28E3f07A2E3cd707c9698a"; // contract address
  const slotNumber = 0; // slot number
  const rpcURL = hre.network.config.url; // get rpc from hardhat.config.js

  let printLogs = {
    contract: contractAddress,
    slotNumber: slotNumber,
    rpcURL: rpcURL,
  };

  console.log(printLogs);

  await getStorageValue(rpcURL, contractAddress, slotNumber);
}

main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});
```

3. Execute the following command in your terminal to run the getStorage script using the Swisstronik network

```
npx hardhat run scripts/getStorage.js --network swisstronik
```

4. Execute the following command in your terminal to run the getStorage script using the ETH Sepolia network

```
npx hardhat run scripts/getStorage.js --network sepolia
```

5. Execute the following command in your terminal to run the getStorage script using the Polygon Mumbai network

```
npx hardhat run scripts/getStorage.js --network mumbai
```

6. Upon successful execution, your terminal should display the latest message you've defined in the contract 🎉

<figure><img src="/files/jhxXZvbJHvu7klIRp9HD" alt=""><figcaption><p><em>The output should like this</em> </p></figcaption></figure>

***

`01. Provide an explanation of the value retrieved from the RPC call.`\
\
✅ Swisstronik Network:\
✔ Value: 0xc73e7f645a2bf1365a0903afa03a2cb5029ba989df7844b0fe7751b1ba918ea4\
✔ Explanation: This hexadecimal string represents the raw data stored in the contract's first storage slot, which corresponds to the private message variable. The value 0xc73e7f645a2bf1365a0903afa03a2cb5029ba989df7844b0fe7751b1ba918ea4 encodes the current message stored in the contract. This value can change when someone calls the setMessage() function to update the message.\
\
✅ Mumbai Network and Sepolia Network:\
✔ Value: 0x0000000000000000000000000000000000000000000000000000000000000000\
✔ Explanation: These values are also hexadecimal strings, but they consist entirely of zeros. This suggests that either no meaningful data was stored in the first storage slot of the contract on these networks. Essentially, it indicates that there is no message stored in the contract on these networks, or the message is an empty string.\
\
`02. What does this retrieved value represent? Is there any difference if this RPC call is made on the Sepolia or Mumbai networks?`\
\
✅ Swisstronik Network, you are seeing the encoded or hashed representation of the current message stored in the contract's first storage slot.\
✅ Mumbai and Sepolia Networks, you are seeing all zeros in the first storage slot, indicating an empty message or no message has been set on these networks for the given contract.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.logosnodos.online/solidity-compiler/hardhat/json-rpc-call-using-eth-getstorage.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
