A simple and efficient Ethereum smart contract for storing key-value data with event logging, designed for decentralized data storage applications.
The SaveContract provides functionality to store structured data in a key-field-value format and emit events when data is saved. It offers two flexible methods for data storage:
- Struct Method: Save using a
DataItemstruct for organized data handling - Parameter Method: Save using individual string parameters for simple operations
struct DataItem {
string key;
string field;
string value;
}
function save(DataItem memory _data) public
function save(string memory _key, string memory _field, string memory _value) public
event DataSaved(string key, string field, string value)- Go 1.23.0 - Download and install Go
- Solidity Compiler (solc) - Installation guide
- Local Ethereum Environment - Choose one:
-
Start a local Ethereum node using Geth:
# Start Geth geth --dev --http --http.api eth,web3,net --http.corsdomain "https://remix.ethereum.org"
Alternatively, you can use other development environments like ganache.
-
Clone the repository:
git clone https://github.com/casibase/contract-storage-eth.git cd contract-storage-eth -
Verify Solidity compiler installation:
To compile the contract, use the Solidity compiler (
solc). Ensure thatsolcis installed on your system. If it is not installed, follow the instructions at soliditylang.org to install it.After installation, verify it by running:
solc --version
-
Compile the contract to get bytecode and ABI:
solc --bin --abi Storage.sol -o build/
This command compiles the
Storage.solcontract and outputs the bytecode and ABI files into thebuild/directory. -
Configure deployment settings:
Edit
config.yamlto set your JSON-RPC endpoint and private key:# config.yaml ethereum: # Ethereum node connection URL rpc_url: "http://127.0.0.1:8545" # Private key (without 0x prefix) private_key: "YOUR_PRIVATE_KEY_HERE"
Security Note: Replace
"YOUR_PRIVATE_KEY_HERE"with your Ethereum account's private key. For development, you can use the default account generated by Geth in dev mode.b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291 -
Run the deployment script:
Execute the deployment script:
go run deploy.go
The Go script will:
- Connect to your local Ethereum node (configured in
config.yaml) - Deploy the
SaveContractto the blockchain - Test the contract by calling both
savefunctions - Display transaction hashes and contract address
- Connect to your local Ethereum node (configured in
For users who prefer a web-based approach:
-
Prepare your environment:
- Start your local Ethereum node (as shown above)
- Open Remix IDE in your browser
-
Create and compile the contract:
- Upload the
Storage.solfile to Remix - Go to the "Solidity Compiler" tab
- Select compiler version
0.8.0or higher - Click "Compile Storage.sol"
- Upload the
-
Connect to your local node:
- Navigate to the "Deploy & Run Transactions" tab
- In "Environment", select "External Http Provider"
- Enter your node URL:
http://127.0.0.1:8545
-
Deploy and interact:
- Select
SaveContractin the contract dropdown - Click "Deploy" and confirm the transaction
- Use the deployed contract interface to test functions
- Select
We welcome contributions! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.