Skip to main content

Example Contracts

The Stellar team has put together a large collection of example contracts to demonstrate use of smart contracts on Stellar. For many of these example contracts, we've written an accompanying tutorial that will walk you through the example contract and describe a bit more about its design.

The examples listed below are provided in a sequential manner. The first listed example contracts create a solid foundation of concepts that will be required during the later examples. While you are absolutely free to choose, read, and use any of the example contracts you like, please keep in mind that the order you see is intentional.

Events - Publish events from a smart contract.

Custom Types - Define your own data structures in a smart contract.

Errors - Define and generate errors in a smart contract.

Logging - Debug a smart contract with logs.

Auth - Implement authentication and authorization.

Cross Contract Calls - Call a smart contract from another smart contract.

Deployer - Deploy and initialize a smart contract using another smart contract.

Allocator - Use the allocator feature to emulate heap memory in a smart contract.

Atomic Swap - Swap tokens atomically between authorized users.

Batched Atomic Swaps - Swap a token pair among groups of authorized users.

Timelock - Lockup some token to be claimed by another user under set conditions.

Single Offer Sale - Make a standing offer to sell a token in exchange for another token.

Liquidity Pool - Write a constant-product liquidity pool contract.

Tokens - Write a CAP-46-6 compliant token contract.

Custom Account - Implement an account contract supporting multisig and custom authorization policies.

Fuzz Testing - Increase confidence in a contract's correctness with fuzz testing.