Skip to content

Crypto-Jaguars/Revo-Contracts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

40 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Revo Contracts

πŸ› οΈ Maintainer

maintainer 1

Software Engineer | OSS contributor

Matias
Telegram

πŸ“– Table of Contents

  1. πŸ“œ Prerequisites
  2. πŸ–₯️ Environment Setup
  3. πŸ’³ Wallet Configuration
  4. πŸš€ Compilation and Deployment
  5. πŸ•΅πŸ» Testing and Execution
  6. πŸ”© Practical Example
  7. 🩺 Troubleshooting

πŸ“ Prerequisites

Before getting started, make sure you have the following installed on your system:

1. Installing Rust πŸ¦€:

  • For Linux 🐧, macOS 🍎 Systems

    If you using macOS, Linux, or any other Unix-like system:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  • Windows πŸͺŸ:

    Download Rust and run rustup-init.exe.

    • Install the wasm32 target:

      After installing Rust, add the wasm32-unknown-unknown target:
    rustup target add wasm32-unknown-unknown

2. Install Stellar CLI πŸ“‘:

  1. There are a few ways to install the latest version of Stellar CLI.
  2. Rust allows you to use cargo command in the terminal to install the Stellar CLI.
  • Install with cargo πŸ“¦:

cargo install --locked stellar-cli --features opt
  • Install with Homebrew (macOS, Linux):

brew install stellar-cli

Environment Setup πŸ› οΈ

  • Clone the repository πŸ—‚οΈ:

    git clone https://github.com/<username>/Revo-Contracts.git
    cd ./Revo-Contracts
  • build the smart contract πŸ‘·β€β™‚οΈ:

    stellar contract build
  • Run the Tests πŸ•΅οΈ:

    cargo test

Wallet Configuration πŸ’³

  1. Install the Stellar Wallet (e.g., Freighter Wallet).
  2. Create a wallet and save the secret keys πŸ”‘ securely.
  3. Connect wallet to the Stellar test network.

Compilation and Deployment πŸš€

1. Build contract πŸ‘·β€β™‚οΈ:

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.

2. Deploy contract 🧨:

To deploy the smart contract to the Stellar testnet, run the following command:

  • macOS/Linux πŸ’Ώ:

stellar contract deploy \
   --wasm-hash <wasm_hash> \
   --source <source_account> \
   --network <network>

This command will deploy the contract to the testnet and return the contract's address.

ExampleπŸ’‘:

  • Assume the following values:
    • <wasm_hash>: ./target/wasm32-unknown-unknown/release/stellar_smart_contract.wasm \
    • <source_account>: GBZXN7PIRZGNWCXXFYU7KYWXX4BXZUYHZO5QUEMKRHLUVLYN53WVFG3E
    • : testnet
stellar contract deploy \
   --wasm ./target/wasm32-unknown-unknown/release/stellar_smart_contract.wasm \
   --source GBZXN7PIRZGNWCXXFYU7KYWXX4BXZUYHZO5QUEMKRHLUVLYN53WVFG3E \
   --network testnet  

Where:

  • <wasm_hash> is the hash of the .wasm file generated during the contract installation.
  • <source_account> is the account from which the deployment will be made.
  • <network> is the network you are working on (e.g., testnet).

Testing and Execution πŸ”¬

To run the tests, execute the following command:

cargo test

Fix any errors and re-run the tests.

Interact with contract πŸ€–:

  • Simulate contract calls to ensure correctness:
stellar contract invoke \
   --contract-id <contract_id> \
   --source <source_account> \
   --network <network> \
   --function <function_name> \
   --args <function_arguments>

Where:

  • <contract_id> is the deployed contract ID.
  • <function_name> is the function being tested.

Practical Example πŸ‘©πŸ»β€πŸ’»

Installation πŸ“¦:

Install all prerequisites,If not installed.

Create New Project 🎨:

Create a new project using the init command to create a soroban-hello-world project.

stellar contract init soroban-hello-world

The init command will create a Rust workspace project structure 🩻:

.
β”œβ”€β”€ Cargo.lock
β”œβ”€β”€ Cargo.toml
β”œβ”€β”€ README.md
└── contracts
    └── hello_world
        β”œβ”€β”€ Cargo.toml
        └── src
            β”œβ”€β”€ lib.rs
            └── test.rs
  • add simple contract in contracts/hello_world/src/lib.rs :
#![no_std]
use soroban_sdk::{contract, contractimpl, symbol_short, vec, Env, Symbol, Vec};

#[contract]
pub struct HelloContract;

#[contractimpl]
impl HelloContract {
    pub fn hello(env: Env, to: Symbol) -> Vec<Symbol> {
        vec![&env, symbol_short!("Hello"), to]
    }
}

mod test;
  • Add test contract file contracts/hello_world/src/test.rs:
#![cfg(test)]

use super::*;
use soroban_sdk::{symbol_short, vec, Env};

#[test]
fn test() {
    let env = Env::default();
    let contract_id = env.register_contract(None, HelloContract);
    let client = HelloContractClient::new(&env, &contract_id);

    let words = client.hello(&symbol_short!("Dev"));
    assert_eq!(
        words,
        vec![&env, symbol_short!("Hello"), symbol_short!("Dev"),]
    );
}

Run the Tests πŸ•΅οΈ:

Run cargo test and watch the unit test run. You should see the following output:

cargo test
running 1 test
test test::test ... ok

Build the contract πŸ—οΈ:

To build a smart contract to deploy or run, use the stellar contract build command.

stellar contract build

Deploy to Testnet πŸš€:

To deploy your HelloWorld contract, run the following command:

stellar contract deploy \
  --wasm target/wasm32-unknown-unknown/release/hello_world.wasm \
  --source alice \
  --network testnet

This returns the contract id CACDYF3CYMJEJTIVFESQYZTN67GO2R5D5IUABTCUG3HXQSRXCSOROBAN, so replace it with your actual contract id.

Interact πŸ”:

run the following command to invoke the hello function.

stellar contract invoke \
  --id CACDYF3CYMJEJTIVFESQYZTN67GO2R5D5IUABTCUG3HXQSRXCSOROBAN \
  --source alice \
  --network testnet \
  -- \
  hello \
  --to RPC

output should appear:

["Hello", "RPC"]

Summary 🎯

In this example , we learned how to:

  • deploy a contract to Testnet
  • interact with a deployed contract

Troubleshooting 🩺:

Common Issues and FixesπŸ€”:

  1. πŸ¦€Rust Installation Issues:

    • Ensure cargo is in your system PATH.
  2. πŸ“‘Stellar CLI Errors:

    • Verify the version compatibility of the Stellar CLI.
    • Use the --help flag to get details of commands:
     stellar --help
  3. πŸ’ΈWallet Connectivity:

    • Double-check network configuration (testnet/mainnet).

By following this guide, you should be able to set up your environment and deploy a basic Smart Contract using Stellar. Always refer to the official Stellar documentation for the most up-to-date information and best practices

About

This is the Revo-Contracts Repository

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages