ErgoScript By Example

Learn ErgoScript by reading example smart contracts powered by the Ergo Playground.

Each contract example includes a Ergo Playground link which allows you to instantly edit and run the smart contract code inside of your browser.

If you ever need clarity about how specific types/functions/operators in ErgoScript work, please reference the ErgoScript Language Description.

For an overarching summary of how everything in this repo works, please reference the video below:

ErgoScript By Example & Ergo Playground Introductory Video

Table Of Contents

ErgoScript Examples

Number Difficulty Title
1 Beginner Pin Lock Contract
2 Intermediate Single-Chain Swap Contracts

Extra Resources To Get Started

If you are unfamiliar with the Extended UTXO model, smart contracts, or Ergo specifically, the above examples may be a little bit challenging to jump straight into. As such the following links below are recommended resources for getting a solid background in understanding what is going on:

  1. Emurgo Research: How Do UTXO Contracts Work? (First 2 sections)

  2. ErgoScript Whitepaper

  3. Advanced ErgoScript Whitepaper

  4. Emurgo Research: High Level Design Patterns In EUTXO Systems

The first two links should enlighten you to the majority of the basics, and the links thereafter are more advanced deep dives.

How To Contribute

We are always happy to include new community-submitted examples within this repo if you are interested in contributing.

All examples submitted must:

  • Use the Ergo Playground via Scastie (basic template here)
  • Create a test scenario to show off the off-chain logic required for the contract to work
  • Provide clear comments inside of the code explaining what is going on
  • Follow the example template. (Ensure you include your scastie Ergo Playground url in both links)
  • Have an understandable/relevant title + filename

Simply create a PR with your new exampleTitle.md file added to the repo + this README.md updated with your example added to the list of ErgoScript Examples.

If you are unsure about anything feel free to reference the first example contract and/or join the Ergo Discord to ask questions.