A curated collection of production-ready Soroban smart contract templates. These templates help developers quickly bootstrap common use cases on Soroban (Stellar's smart contract platform) for DeFi, payments, governance, and more.
# Clone the repository
git clone https://github.com/your-username/soroban-contract-templates.git
cd soroban-contract-templates
# Build a contract (example: token)
cd contracts/token
stellar contract build
# Deploy to testnet
./scripts/deploy.sh testnet
# Run tests
cargo test| Template | Description | Use Cases | Status |
|---|---|---|---|
| Token | Custom fungible token with mint/burn/admin controls | DeFi tokens, governance tokens, utility tokens | ✅ Complete |
| Escrow | Two-party escrow with timeout and refund mechanism | P2P trading, service payments, milestone payments | ✅ Complete |
- Standard Interface: Full Soroban token compatibility
- Administrative Controls: Mint, burn, and admin management
- Metadata Support: Name, symbol, and decimals
- Allowance System: Approve and transfer_from functionality
- Event Emission: All operations emit events for tracking
- Error Handling: Custom error types for better debugging
- Two-Party Security: Secure buyer-seller transactions
- Deadline Protection: Automatic refunds after deadline
- Arbiter Support: Third-party dispute resolution
- State Management: Clear transaction lifecycle
- Token Agnostic: Works with any Soroban token
- Event Emission: All operations emit events for tracking
Each template includes:
- ✅ Complete contract implementation
- ✅ Comprehensive unit tests (8+ test cases each)
- ✅ Deployment scripts with examples
- ✅ Usage examples and documentation
- Rust (latest stable)
- Soroban CLI
- Docker (for local Stellar node)
cd contracts/[template-name]
stellar contract buildcd contracts/[template-name]
cargo testcd contracts/[template-name]
./scripts/deploy.sh testnetStart a local Stellar node with Soroban RPC:
docker compose up stellar-node| Code | Name | Description |
|---|---|---|
| 1 | InsufficientBalance |
Caller's balance is too low to complete the transfer or burn |
| 2 | InsufficientAllowance |
Approved allowance is too low for the requested transfer_from amount |
| 3 | Unauthorized |
Caller is not the admin or does not have permission for this operation |
| 4 | AlreadyInitialized |
initialize was called on a contract that has already been set up |
| 5 | NotInitialized |
An operation was attempted before the contract was initialized |
| 6 | InvalidAmount |
Amount is zero, negative, or exceeds the configured max supply |
| 7 | Overflow |
Arithmetic overflow occurred during a balance or supply calculation |
| Code | Name | Description |
|---|---|---|
| 1 | NotAuthorized |
Caller is not permitted to invoke this function (wrong party or arbiter) |
| 2 | InvalidState |
The escrow is not in the required state for this operation |
| 3 | DeadlinePassed |
The escrow deadline has already elapsed; the operation is no longer valid |
| 4 | DeadlineNotReached |
The deadline has not yet passed; premature refund or timeout claim attempted |
| 5 | AlreadyInitialized |
initialize was called on an escrow that is already set up |
| 6 | NotInitialized |
An operation was attempted before the escrow was initialized |
| 7 | InsufficientFunds |
The buyer's token balance is too low to cover the escrowed amount |
| 8 | InvalidAmount |
The specified amount is zero or otherwise invalid |
| 9 | InvalidParties |
Buyer, seller, or arbiter addresses are invalid or conflict with each other |
We welcome contributions! See CONTRIBUTING.md for dev setup, test commands, code style, and the PR process.
- Soroban Documentation
- Stellar Developer Discord
- Soroban Examples
- Freighter Wallet
- Stellar Laboratory
- Security Best Practices
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Ready to build on Soroban? Start with any template and customize it for your use case! 🚀