Skip to content

Commit ba14d8b

Browse files
Merge pull request #136 from emteebug12-jpg/feature/escrow-deploy-126
feat(escrow): add Soroban escrow deploy script and docs\n\nCloses #126
2 parents dd7eed3 + 5ac8a3f commit ba14d8b

3 files changed

Lines changed: 120 additions & 0 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ Future work may introduce an alternative CI/CD pipeline (e.g., a different provi
159159

160160
---
161161

162+
## Soroban Escrow Deployment
163+
164+
See the Soroban escrow deployment guide for build and deploy steps, example CLI calls, and integration notes: [docs/soroban-escrow-deployment.md](docs/soroban-escrow-deployment.md)
165+
166+
162167
## 📄 License
163168

164169
This project is licensed under the **MIT License**. See the [LICENSE](LICENSE) file for details.

contracts/deploy_escrow_testnet.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Simple helper to build the escrow contract WASM and show how to deploy it
5+
# to the Soroban / Stellar Testnet using the `soroban` CLI.
6+
#
7+
# Prerequisites:
8+
# - Rust + cargo (with wasm32 target installed)
9+
# - `soroban` CLI available in PATH
10+
# - SOROBAN_RPC_URL set (defaults to https://rpc.testnet.soroban.stellar.org)
11+
12+
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
13+
CONTRACT_DIR="$ROOT_DIR/contracts/escrow"
14+
15+
echo "[escrow deploy] Building escrow contract..."
16+
cd "$CONTRACT_DIR"
17+
18+
# Prefer standard cargo build for wasm target; the project Makefile also
19+
# provides `stellar contract build` which may be available in some setups.
20+
echo "[escrow deploy] Running cargo build (wasm32-unknown-unknown, release)"
21+
cargo build --release --target wasm32-unknown-unknown || {
22+
echo "cargo build failed — you may need to run 'stellar contract build' or ensure wasm target is installed"
23+
exit 1
24+
}
25+
26+
WASM_PATH="$CONTRACT_DIR/target/wasm32-unknown-unknown/release/escrow.wasm"
27+
if [ ! -f "$WASM_PATH" ]; then
28+
echo "WASM not found at $WASM_PATH"
29+
exit 1
30+
fi
31+
32+
SOROBAN_RPC_URL="${SOROBAN_RPC_URL:-https://rpc.testnet.soroban.stellar.org}"
33+
export SOROBAN_RPC_URL
34+
echo "[escrow deploy] Using SOROBAN_RPC_URL=$SOROBAN_RPC_URL"
35+
36+
if ! command -v soroban >/dev/null 2>&1; then
37+
echo "soroban CLI not found in PATH. Install from: https://github.com/stellar/soroban-tools"
38+
exit 1
39+
fi
40+
41+
echo "\nBuilt WASM: $WASM_PATH"
42+
echo "\nTo deploy the contract to the configured Soroban RPC, run:"
43+
echo "\n soroban contract deploy --wasm $WASM_PATH\n"
44+
45+
echo "The `soroban contract deploy` command will submit a transaction and print the resulting contract ID and tx hash."
46+
echo "After deployment, you can call the contract methods (fund, release, refund, etc.) using `soroban contract invoke`."
47+
48+
echo "If you want this script to run the deploy step automatically, set AUTO_DEPLOY=1 in the environment."
49+
if [ "${AUTO_DEPLOY:-0}" = "1" ]; then
50+
echo "[escrow deploy] AUTO_DEPLOY=1 detected — running deployment now..."
51+
soroban contract deploy --wasm "$WASM_PATH"
52+
fi
53+
54+
echo "\nDone. See docs/soroban-escrow-deployment.md for full instructions and examples."

docs/soroban-escrow-deployment.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Soroban Escrow Contract — Deployment Guide
2+
3+
This guide explains how to build and deploy the `escrow` Soroban contract included under `contracts/contracts/escrow` to the Stellar Testnet (Soroban).
4+
5+
Prerequisites
6+
- Rust + cargo and the `wasm32-unknown-unknown` target installed:
7+
- `rustup target add wasm32-unknown-unknown`
8+
- `soroban` CLI installed and available in your PATH (see https://github.com/stellar/soroban-tools)
9+
- Network RPC for Soroban testnet (the script defaults to `https://rpc.testnet.soroban.stellar.org`)
10+
11+
Quick build & deploy
12+
13+
1. Build the WASM artifact:
14+
15+
```bash
16+
cd contracts
17+
./deploy_escrow_testnet.sh
18+
```
19+
20+
The script builds the contract and prints the command you can run to deploy using the `soroban` CLI. If you set `AUTO_DEPLOY=1` it will attempt to run the deploy command automatically.
21+
22+
Environment variables
23+
- `SOROBAN_RPC_URL` — optional. If unset the script uses `https://rpc.testnet.soroban.stellar.org`.
24+
- `AUTO_DEPLOY=1` — run the deploy command automatically after building.
25+
26+
Example: manual deploy (after building)
27+
28+
```bash
29+
# deploy the compiled wasm (prints tx hash and contract id)
30+
soroban contract deploy --wasm contracts/contracts/escrow/target/wasm32-unknown-unknown/release/escrow.wasm
31+
32+
# example: call `fund` as the client (requires the client key available to soroban CLI)
33+
soroban contract invoke --id <CONTRACT_ID> --fn fund --source <CLIENT_SECRET>
34+
35+
# example: release payment (either client or freelancer can call; pass the caller address as an argument if required)
36+
soroban contract invoke --id <CONTRACT_ID> --fn release --args <MILESTONE_ID> <CALLER_ADDRESS> --source <CALLER_SECRET>
37+
38+
# example: refund (freelancer invokes)
39+
soroban contract invoke --id <CONTRACT_ID> --fn refund --args <MILESTONE_ID> <CALLER_ADDRESS> --source <FREELANCER_SECRET>
40+
```
41+
42+
Notes on contract functions and mapping
43+
- `initialize(...)` — creates an escrow (maps to requested `create_escrow`).
44+
- `fund()` — lock funds into the contract (maps to `fund_escrow`).
45+
- `submit_milestone(milestone_id)` — freelancer submits completed milestone.
46+
- `approve(milestone_id)` — client approves submitted milestone.
47+
- `freelancer_confirm(milestone_id)` — freelancer confirms approval.
48+
- `release(milestone_id, caller)` — releases funds to freelancer (maps to `release_payment`).
49+
- `refund(milestone_id, caller)` — refunds client (maps to `refund_payment`).
50+
- `dispute(...)` / `resolve_dispute(...)` — dispute and arbiter resolution.
51+
52+
Integration notes
53+
- The contract expects an SPL-like token address (`token`) passed at initialization. The contract uses the standard `token::Client` interface for transfers.
54+
- Constructing the initialization `milestones` vector via CLI can be complex; for integration we recommend using the `@stellar/stellar-sdk` / Soroban client in an application script to upload WASM and call `initialize` with typed arguments.
55+
56+
Replacing the JS stub
57+
- The repository contains a JS stub at `lib/soroban/deploy.ts`. Replace that stub with an implementation that uploads the compiled WASM, sends the install/create contract transaction, and returns the deployed contract ID and tx hash. See notes in that file for steps.
58+
59+
Further reading
60+
- Soroban RPC & CLI docs: https://soroban.stellar.org
61+
- Soroban developer docs: https://soroban.stellar.org/docs

0 commit comments

Comments
 (0)