The SimpleStorage
smart contract is designed to perform the following basic functions:
-
Storing Data: It allows users to store a single string value on the Ethereum blockchain.
-
Updating Data: Users can update the stored string value with a new one.
-
Retrieving Data: It provides the ability to retrieve the currently stored string value.
- Solidity Version: ^0.8.0
- License: MIT
- Description: This function enables users to update the stored string value. The new string replaces the existing one.
newData
(string): The new string value to be stored.
- Description: This read-only function allows users to retrieve the current string value stored in the contract.
string
: The current string value stored in the contract.
-
Setting a New Value: Use the
setData
function to update the stored string value:simpleStorage.setData("New Value");
-
Retrieving the Current Value: Retrieve the current string value using the
getData
function:string currentValue = simpleStorage.getData();
After executing this line,
currentValue
will contain the current value stored in the contract.
- This smart contract serves as a basic example of how to store and retrieve data on the Ethereum blockchain. It does not implement advanced access control or security features and is intended for educational purposes.
Certainly, here's a documentation for the provided script that explains its functionality:
The Ethereum Storage Retrieval Script is a Node.js script that retrieves storage variables from Ethereum smart contracts on specified Ethereum networks. It uses the eth_getStorageAt
RPC method to access storage slots in smart contracts and extract data from them.
- Script Name: Ethereum Storage Retrieval Script
- Dependencies: ethers.js, hardhat, @swisstronik/swisstronik.js, dotenv
- Configuration: Requires a
deployedContracts.json
file and a.env
file for environment variables.
The script performs the following tasks:
-
Load Contract Information: It loads contract information from a JSON file named
deployedContracts.json
. This file should contain details about the contracts to be queried, including their addresses. -
Network Configurations: It defines network configurations for Ethereum networks to be queried. The script supports the Polygon Mumbai network and a custom network named "swisstronik" with a specified provider URL.
-
Storage Value Retrieval: The script iterates through the contracts specified in the loaded contract information. For each contract, it retrieves the storage value using the
eth_getStorageAt
RPC method. The script retrieves the value stored in slot0x0
, which corresponds to the first storage slot of the contract. -
Logging: It logs the retrieved storage values, indicating from which network they were retrieved.
-
Error Handling: The script includes error handling to gracefully handle any unexpected issues during execution.
-
Prerequisites: Before running the script, ensure you have the following prerequisites in place:
- The
deployedContracts.json
file containing contract information. - The
.env
file containing environment variables, especially the Alchemy API key if querying the Polygon Mumbai network.
- The
-
Installation: Make sure you have the required dependencies installed by running:
npm install ethers hardhat @swisstronik/swisstronik.js dotenv
-
Execution: Run the script using Node.js as follows:
node script.js
Replace
script.js
with the name of your script file. -
Results: The script will retrieve and display the storage values from the specified Ethereum networks.
- This script demonstrates how to use ethers.js and the
eth_getStorageAt
method to interact with Ethereum smart contracts and retrieve storage values. - Ensure that you have the correct contract information in the
deployedContracts.json
file. - Protect sensitive information, such as API keys and private keys, by storing them securely and using environment variables.
- Customize the network configurations and error handling as needed for your specific use case.