Skip to content

ErgoScript

Key Concepts

  • Ergo is a UTXO based blockchain with Proof-of-Work consensus
  • Ergo is considered an extended-UTXO model, supporting advanced financial contracts similar to those in Ethereum's account-based model
  • Since Ergo is UTXO based, therefore ErgoScript has many UTXO-specific constructs such as:
  • Box, INPUTS, OUTPUTS
  • 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 the OUTPUTS 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 the OUTPUTS array
  • Unlike Scala, ErgoScript does not support the var keyword, and thus everything is immutable
  • The scripting language in itself 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
  1. Allows Only Alice to spend a box before a certain height
  2. 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

Tutorials

Advanced Tutorials

Explanations

References

Examples

Visual

Bookmarks

P2S

You can do some simple apps with just the node and ErgoScript to P2S address compiler available at wallet.plutomonkey.com/p2s. A transaction to this P2S or pay-to-script address will create an output locked with the script

P2SH

Typically most people use P2S because it is a lot easier to use. P2SH means you have to keep the contract ready off-chain to be submitted when you create the transaction, and if you lose it, then your funds are stuck forever. This also makes it harder for other people to use your dApp as they need the contract themselves, rather than just the address. P2SH is technically cheaper since you store less data on-chain, but likely we won't see anyone using P2SH until we start to get heavy load on-chain.

Box

Here is a box to experiment with - this address will create an output at this box