This repository contains a simple Soroban smart contract that functions as a key-value store, along with a React frontend that interacts with the contract using the Stellar-SDK.
The Soroban smart contract allows you to:
- Set a key-value pair
- Get the value of a specific key
- Remove a key-value pair
The React application allows users to:
- Set key-value pairs in the Soroban smart contract.
- Retrieve values by key from the Soroban smart contract.
Before getting started, ensure you have the following installed:
- Rust and cargo: For compiling and deploying the Soroban contract.
- Node.js and npm: For running the React application.
- Soroban CLI: For interacting with the Soroban network.
git clone https://github.com/jamesbachini/Stellar-Soroban-Boilerplate.git
cd Stellar-Soroban-Boilerplate
Make sure you have the Soroban CLI set up to interact with the Soroban testnet.
Run the following command to compile the Soroban smart contract:
cd contract
cargo build --target wasm32-unknown-unknown --release
This will generate a .wasm
file in the target/wasm32-unknown-unknown/release/
directory.
To deploy the contract on Soroban's testnet, use the Soroban CLI:
soroban contract deploy \
--wasm target/wasm32-unknown-unknown/release/YOUR_CONTRACT_NAME.wasm \
--network soroban-testnet
After deploying, you'll get a contract ID that is required in the React app to interact with the contract.
From the root of the project (or inside the client/
directory if split), install the React app's dependencies:
npm install
In the App.js
file, replace the contractId
with the one you obtained after deploying the contract:
const contractId = 'YOUR_DEPLOYED_CONTRACT_ID';
To start the development server, run:
npm start
The app will be available at http://localhost:3000
.
- In the Set Key-Value Pair section, enter the key and value you want to store.
- Click the Set button.
- The transaction will be processed and the key-value pair will be stored in the Soroban contract.
- In the Get Value by Key section, enter the key for which you want to retrieve the value.
- Click the Get button.
- If the key exists, the value will be displayed.
There is a remove functionality implemented in the smart contract. To add this feature to the UI, you can extend the React app to call the remove
method.
- Soroban – Smart contract platform built by Stellar.
- Stellar SDK – JavaScript SDK for interacting with the Stellar network.
This project is licensed under the MIT License.