Find the YouTube video tutorial here.
This repository contains a basic example of a Stellar smart contract written in Rust. It includes all the necessary instructions to build, deploy, and interact with the contract on the Stellar testnet.
- Prerequisites
- Installation
- Building the Contract
- Set up local Source Account
- Deploying the Contract
- Interacting with the Contract
- Running Tests
- Project Structure
- License
Before you begin, ensure you have the following tools installed:
- Rust: The Rust programming language. You can install it using rustup.
- Soroban CLI: The Stellar CLI tool for working with smart contracts. Installation instructions.
- Cargo: Rust's package manager, installed automatically with Rust.
-
Clone the repository:
git clone https://github.com/danieljancar/stellar-smart-contract.git cd stellar-smart-contract
-
Install Rust (if you haven't already):
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
-
Install the Soroban CLI:
cargo install soroban-cli
To build the smart contract, run the following command:
stellar contract build
This command will compile the contract and generate a contract.wasm
file in the target/deploy
directory.
To deploy the contract to the Stellar testnet, you need to set up a local source account. You can create a new account using the following command:
stellar keys generate alice \
--rpc-url https://horizon-testnet.stellar.org \
--network-passphrase "Test SDF Network ; September 2015" \
--network testnet
To deploy the smart contract to the Stellar testnet, run the following command:
stellar contract deploy \
--wasm ./target/wasm32-unknown-unknown/release/stellar_smart_contract.wasm \
--source-account alice \
--network testnet
This command will deploy the contract to the testnet and return the contract's address.
To save a value to the contract, run the following command:
stellar contract invoke \
--id <YOUR_CONTRACT_ID> \
--source-account alice \
--network testnet \
-- \
save_value --key "brogramming_lang" --value "rust"
To get a value from the contract, run the following command:
stellar contract invoke \
--id <YOUR_CONTRACT_ID> \
--source-account alice \
--network testnet \
-- \
get_value --key "brogramming_lang"
To run the tests, execute the following command:
cargo test
The project is structured as follows:
src/
: Contains the Rust source code for the smart contract and tests.Cargo.toml
: The project manifest file that contains dependencies and metadata.
This project is licensed under the MIT License - see the LICENSE file for details.