|
| 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