Skip to content

padparadscho/zig-soroban-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Zig Soroban Examples

A collection of Soroban smart contract examples written in Zig. The examples illustrate how to use the features, in their simplest form.

Prerequisites

Identities Setup

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

Zig Soroban SDK

This project uses the zig-soroban-sdk by Leigh McCulloch.

Examples

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

Build the contract:

# Example: Build the 'hello' contract
zig build hello

Compiled WASM file is output to zig-out/bin/hello.wasm.

Deploy

Deploy to Stellar Testnet:

# Example: Deploy the 'hello' contract
stellar contract deploy --wasm zig-out/bin/hello.wasm --alias hello --source deployer --network testnet

Invoke

Invoke the contract:

# Example: Invoke the 'hello' contract
stellar contract invoke --id hello --source user --network testnet -- hello --to world

Project Structure

zig-soroban-examples/
├── build.zig               # Build configuration
├── build.zig.zon           # Dependencies
├── README.md
└── examples/
    ├── hello/              # Hello World example
    │   └── contract.zig
    └── ...                 # Additional examples

License

This project is licensed under the MIT License.

About

A collection of Soroban smart contract examples written in Zig.

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages