Skip to content

casibase/contract-storage-eth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

contract-storage-eth

License Go Version Solidity

A simple and efficient Ethereum smart contract for storing key-value data with event logging, designed for decentralized data storage applications.

Table of Contents

Contract Overview

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 DataItem struct for organized data handling
  • Parameter Method: Save using individual string parameters for simple operations

Contract Interface

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)

Prerequisites

Deployment

Prerequisites for Deployment

  1. 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.

Method 1: Deploy using Go

  1. Clone the repository:

    git clone https://github.com/casibase/contract-storage-eth.git
    cd contract-storage-eth
  2. Verify Solidity compiler installation:

    To compile the contract, use the Solidity compiler (solc). Ensure that solc is 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
  3. Compile the contract to get bytecode and ABI:

    solc --bin --abi Storage.sol -o build/

    This command compiles the Storage.sol contract and outputs the bytecode and ABI files into the build/ directory.

  4. Configure deployment settings:

    Edit config.yaml to 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

  5. 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 SaveContract to the blockchain
    • Test the contract by calling both save functions
    • Display transaction hashes and contract address

Method 2: Deploy using Remix IDE

For users who prefer a web-based approach:

  1. Prepare your environment:

    • Start your local Ethereum node (as shown above)
    • Open Remix IDE in your browser
  2. Create and compile the contract:

    • Upload the Storage.sol file to Remix
    • Go to the "Solidity Compiler" tab
    • Select compiler version 0.8.0 or higher
    • Click "Compile Storage.sol"
  3. 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
  4. Deploy and interact:

    • Select SaveContract in the contract dropdown
    • Click "Deploy" and confirm the transaction
    • Use the deployed contract interface to test functions

Contributing

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.

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.