Warning
Due to the experimental status of the Soroban SDK for Zig, these examples are intended for educational purposes and should not be used in production. Use at your own risk.
A collection of Soroban smart contract examples written in Zig. The examples illustrate how to use the features, in their simplest form.
- Zig 0.15.x
- Stellar CLI 25.x
To deploy and interact with the contracts, set up Stellar accounts as needed using the Stellar CLI:
# Create Stellar accounts for deployer, user, sender, admin, etc.
stellar keys generate deployer --network testnet --fundThis project uses the zig-soroban-sdk by Leigh McCulloch.
| Example | Description |
|---|---|
| hello | Demonstrates the basic structure of a Soroban contract |
| increment | Demonstrates a simple counter that can be incremented |
| logging | Demonstrates how to use the standard Soroban terminal logging |
| errors | Demonstrates how to define and handle custom errors |
| events | Demonstrates how to define and emit custom events |
| custom_types | Demonstrates how to define and use custom data structures |
| auth | Demonstrates how to implement basic authentication logic |
| timelock | Demonstrates how to implement time-based conditions |
| cross_contract | Demonstrates how to call another contract from within a contract |
| atomic_swap | Demonstrates a simple atomic swap between two parties |
| deployer | Demonstrates a contract that deploys another contract |
| upgradeable_contract | Demonstrates a simple upgradeable contract pattern |
| ttl | Demonstrates how to manage TTL (Time-To-Live) for contract data |
| alloc | Demonstrates how to use dynamic allocation of Soroban Vec type |
| token | Demonstrates a simple fungible token contract |
Build the contract:
# Example: Build the 'hello' contract
zig build helloCompiled WASM file is output to zig-out/bin/hello.wasm.
Deploy to Stellar Testnet:
# Example: Deploy the 'hello' contract
stellar contract deploy --wasm zig-out/bin/hello.wasm --alias hello --source deployer --network testnetInvoke the contract:
# Example: Invoke the 'hello' contract
stellar contract invoke --id hello --source user --network testnet -- hello --to worldzig-soroban-examples/
├── build.zig # Build configuration
├── build.zig.zon # Dependencies
├── README.md
└── examples/
├── hello/ # Hello World example
│ └── contract.zig
└── ... # Additional examples
This project is licensed under the MIT License.