Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copy this file to .env and customize values as needed for your local
# development or CI environment.

# Soroban network selection (profile name). Valid values: testnet, mainnet, sandbox
SOROBAN_NETWORK=testnet

# Override the RPC endpoint and network passphrase if necessary
SOROBAN_RPC_URL=https://rpc.testnet.soroban.stellar.org
SOROBAN_NETWORK_PASSPHRASE="Test SDF Network ; September 2015"

# Example keypair file path; tools may read this
# SOROBAN_KEY_FILE=./keys/contract-key.json
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/target/
*.exe
*.pdb
*.bin
*.bin

# local environment files
.env
14 changes: 14 additions & 0 deletions .soroban/config/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Soroban CLI network configuration for Contract Fox
# These entries allow `soroban` to resolve the testnet and mainnet
# networks without requiring every developer to add them manually.

# The `network_passphrase` field must exactly match the Stellar network
# passphrase used by the RPC node you are targeting.

[networks.testnet]
rpc_url = "https://rpc.testnet.soroban.stellar.org"
network_passphrase = "Test SDF Network ; September 2015"

[networks.mainnet]
rpc_url = "https://rpc.mainnet.soroban.stellar.org"
network_passphrase = "Public Global Stellar Network ; September 2015"
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ cargo test --workspace

### CLI Usage

For a dedicated guide on building, configuring networks, and running a
simple shell-based deployer, see [docs/DEPLOY.md](docs/DEPLOY.md).


```bash
# Check configuration
cargo run -p stellaraid-tools -- config check
Expand Down
122 changes: 122 additions & 0 deletions docs/DEPLOY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# Deployment Guide

This document covers the steps required to deploy the Soroban smart contracts contained
in this workspace to the **testnet** or **mainnet** networks. It also provides
examples of invoking deployed contracts using the `soroban` CLI.

---

## 1. Prerequisites

- Rust toolchain with `wasm32-unknown-unknown` target installed.
- [Soroban CLI](https://github.com/stellar/soroban-cli) installed and in your `PATH`.
You can install via `cargo install soroban-cli` or `npm install -g soroban-cli`.
- (Optional) [`jq`](https://stedolan.github.io/jq/) for parsing JSON output.

---

## 2. Soroban Network Configuration

The workspace ships with a default configuration at `.soroban/config/config.toml`
that already defines the two public networks. You may still add them manually or
create new profiles:

```bash
# add networks once (these commands update your local soroban config file)
# you only need to run them if you want to modify the RPC URL or passphrase
soroban network add testnet \
--rpc-url https://rpc.testnet.soroban.stellar.org \
--network-passphrase "Test SDF Network ; September 2015"

soroban network add mainnet \
--rpc-url https://rpc.mainnet.soroban.stellar.org \
--network-passphrase "Public Global Stellar Network ; September 2015"

# view available profiles
soroban network ls

# choose an active profile (or set SOROBAN_NETWORK environment variable)
soroban network use testnet
```

> **Note:** the `SOROBAN_RPC_URL` and `SOROBAN_NETWORK_PASSPHRASE` environment
> variables will override whatever values the profile defines. See
> `.env.example` for a template.

---

## 3. Deploying Contracts

A helper script `./scripts/deploy.sh` wraps the common steps:

```sh
# make the script executable if needed
chmod +x ./scripts/deploy.sh

# deploy to testnet (default)
./scripts/deploy.sh testnet

# deploy to mainnet
./scripts/deploy.sh mainnet
```

When executed, the script builds each contract, deploys it to the requested
network, and prints the contract ID returned by the Soroban CLI.

Example output:

```
Building WASM contracts...
Building donation-contract...
Building withdrawal-contract...
Building campaign-contract...
Deploying donation-contract to testnet...
Contract ID: GD5G...7XES
Deploying withdrawal-contract to testnet...
Contract ID: GCFW...9JQK
Deploying campaign-contract to testnet...
Contract ID: GAZQ...3LPT
Deployment script finished.
```

The IDs may be recorded in your own environment (e.g. `.contract_id`) or used
by other automation.

---

## 4. Invoking a Deployed Contract

Once you have a contract ID you can call its methods using `soroban contract
invoke`:

```bash
# simple invocation with no arguments
soroban contract invoke --id GC... --fn ping --network testnet

# with arguments (two string values)
soroban contract invoke --id GC... --fn transfer --network testnet \
--args GABC... PCDE...
```

The same `--network` flag may be replaced by setting `SOROBAN_NETWORK` or by
using `soroban network use` to change the active profile.

---

## 5. Environment Variables

Copy `.env.example` to `.env` and adjust values as necessary. Relevant variables
for deployment include:

```text
SOROBAN_NETWORK=testnet
SOROBAN_RPC_URL=https://rpc.testnet.soroban.stellar.org
SOROBAN_NETWORK_PASSPHRASE="Test SDF Network ; September 2015"
```

Other tooling (friendbot, CLI helpers) may read these values as well.

---

With the above in place you can confidently build, deploy, and interact with the
contracts on either public Soroban network.
57 changes: 57 additions & 0 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env bash
# Simple deployment helper for Contract Fox smart contracts.
# Usage: ./scripts/deploy.sh [network]
# Defaults to "testnet" when no network argument is provided.

set -euo pipefail

if ! command -v soroban >/dev/null 2>&1; then
echo "Error: soroban CLI not found. Install it with 'cargo install soroban-cli' or 'npm install -g soroban-cli'." >&2
exit 1
fi

NETWORK=${1:-testnet}

# ensure profile exists (some soroban versions use "network" subcommand)
if ! soroban network ls | grep -q "^$NETWORK" 2>/dev/null; then
echo "Network profile '$NETWORK' not found, adding default values."
case "$NETWORK" in
testnet)
soroban network add testnet \
--rpc-url https://rpc.testnet.soroban.stellar.org \
--network-passphrase "Test SDF Network ; September 2015"
;;
mainnet)
soroban network add mainnet \
--rpc-url https://rpc.mainnet.soroban.stellar.org \
--network-passphrase "Public Global Stellar Network ; September 2015"
;;
*)
echo "Warning: no automatic configuration for network '$NETWORK'." >&2
;;
esac
fi


# ensure the wasm target is available
rustup target add wasm32-unknown-unknown >/dev/null 2>&1 || true

# build the contracts using the Makefile helper for consistency
echo "Building WASM contracts..."
make build-contracts

CONTRACT_NAMES=("donation-contract" "withdrawal-contract" "campaign-contract")

for name in "${CONTRACT_NAMES[@]}"; do
wasm_file="target/wasm32-unknown-unknown/release/${name}.wasm"
if [ ! -f "$wasm_file" ]; then
echo "WARNING: $wasm_file not found, skipping."
continue
fi
echo "Deploying $name to $NETWORK..."
# soroban outputs a line like "Contract ID: GC..."
soroban contract deploy --wasm "$wasm_file" --network "$NETWORK"
echo
done

echo "Deployment script finished."