Skip to content

smart contracts examples that use the soroban assembly script sdk

License

Notifications You must be signed in to change notification settings

Soneso/as-soroban-examples

Repository files navigation

v0.3.0

AssemblyScript contract examples for Soroban.

Uses the AssemblyScript soroban SDK

Quick Start

1. Clone this repo

2. Install the soroban cli

To run a contract, you must first install the official soroban-cli as described here: stellar soroban cli.

cargo install --locked soroban-cli

3. Run an example contract

Navigate to the directory of the example you would like to run.

cd hello_word

Install the AS Soroban SDK:

npm install

Build the contract:

npm run asbuild:release

You can find the generated .wasm (WebAssembly) file in the build folder. You can also find the .wat file there (Text format of the .wasm).

Run the example contract:

soroban -q contract invoke --wasm build/release.wasm --id 1 --fn hello -- --to friend

4. Available examples

Instead of a tutorial, we have created a series of contract examples with many explanations. It is recommended that you work through the examples in the order shown here.

Example Description
add example Demonstrates how to write a simple contract, with a single function that takes two i32 inputs and returns their sum as an output.
hello word example demonstrates how to write a simple contract, with a single function that takes an input and returns a vector containing multiple host values.
increment example Demonstrates how to write a simple contract that stores data, with a single function that increments an internal counter and returns the value. It also shows how to manage contract data lifetimes and how to optimize contracts.
events example Demonstrates how to publish events from a contract.
errors example Demonstrates how to define and generate errors in a contract that invokers of the contract can understand and handle.
logging example Demonstrates how to log for the purpose of debugging.
auth example Demonstrates how to implement authentication and authorization using the Soroban Host-managed auth framework.
cross contract call example Demonstrates how to call a contract's function from another contract.
deployer example Demonstrates how to deploy contracts using a contract.
upgrading contracts example Demonstrates how to upgrade a wasm contract.
testing example Shows a simple way to test your contract.
token example Demonstrates how to write a token contract that implements the Stellar token interface.
atomic swap example Swaps two tokens between two authorized parties atomically while following the limits they set. This example demonstrates advanced usage of Soroban auth framework and assumes the reader is familiar with the auth example and with Soroban token usage.
atomic swap batched example Swaps a pair of tokens between the two groups of users that authorized the swap operation from the atomic swap example.
timelock example Demonstrates how to write a timelock and implements a greatly simplified claimable balance similar to the claimable balance feature available on Stellar.
single offer sale example The single offer sale example demonstrates how to write a contract that allows a seller to set up an offer to sell token A for token B to multiple buyers.
liquidity pool example Demonstrates how to write a constant product liquidity pool contract.
custom account example This example is an advanced auth example which demonstrates how to implement a simple account contract that supports multisig and customizable authorization policies.

5. Create your own contract

Use: AssemblyScript Soroban SDK