ErgoScript#
ErgoScript is a super-simple subset of Scala. It is a top-level language translated into a low-level language called ErgoTree, which is translated during execution into cryptographic protocol. That's how Ergo supports ring and threshold signatures and much more crypto protocols with no special cases made in the core!
Ergo's support for sigma-protocols (aka generalized Schnorr proofs) are truly unique as building blocks for composable statements. Schnorr protocols and proof-of-Diffie-Hellman-tuples are supported by default, with more options available that the community can add via soft forks.
ErgoScript is built considering Bitcoin’s security and privacy to make all kinds of complex financial contracts accessible. In comparison, Bitcoin’s design doesn’t allow loops or building any complex smart contracts on top of it. ErgoScript allows for self-replication; therefore, we can use it to create Turing-Complete processes in a blockchain.
Key Concepts#
- Ergo is a UTXO-based blockchain with Proof-of-Work consensus
- Ergo uses an extended-UTXO model, supporting advanced financial contracts comparable to those in Ethereum's account-based model.
- Since Ergo is UTXO-based, ErgoScript has many UTXO-specific constructs such as:
Box
,INPUTS
, andOUTPUTS
. A complete list is available here - A Box is essentially a UTXO and consists of up to ten registers for storing data. Similar to Bitcoin, a transaction spends one or more existing boxes (denoted using the
INPUTS
array) and creates one or more new boxes (denoted using theOUTPUTS
array) - ErgoScript's syntax is a subset of Scala's. However, knowledge of Scala is not necessary to learn ErgoScript because the amount of Scala needed to write ErgoScript is small, e.g.
val
- Note that arrays in Scala are accessed using round parentheses, not square brackets like in Java or Python. Thus,
OUTPUTS(0)
refers to the first element of theOUTPUTS
array - Unlike Scala, ErgoScript does not support the
var
keyword, and thus everything is immutable - The scripting language is non-Turing complete, but applications can be made to be Turing complete, as demonstrated in this peer-reviewed paper.
Simple Example#
if (HEIGHT < 100000) alicePubKey else bobPubKey
- Allows Only Alice to spend a box before a certain height
- Allows Only Bob to spend the box after that.
Please see this Quick Primer on ErgoScript for an overview of key concepts and some basic examples.
Resources#
Courses#
- ErgoScript 101 Crash Course (Slides)
- Learn ErgoScript By Example Via The Ergo Playground with Robert Kornacki (Video)
- The ErgoScript Developer Course from DeCo Education
- Deco Education: 2022 Script Class
Tutorials#
Advanced Tutorials#
Explanations#
References#
Examples#
Visual#
- FlowCards is A Declarative Framework for Development of Ergo dApps
- flowcardLib: Ergo FlowCard library for diagrams.net
- ergo-castanet
Bookmarks#
- Compile ErgoScript directly in your browser with ErgoScript Playground
- Kiosk lets anyone play with ErgoScript using a basic web-based UI
- ergoscript-compiler
Box#
Here is a box to experiment with