Skip to content

Core Concepts and Key Principles of ErgoScript#

ErgoScript and the UTXO Model#

  • Ergo is a blockchain platform that operates on the UTXO (Unspent Transaction Output) model and employs a Proof-of-Work consensus mechanism.
  • Ergo introduces an extended-UTXO model that enables the execution of intricate financial contracts, akin to those supported by Ethereum's account-based model.
  • ErgoScript, being aligned with Ergo's UTXO model, incorporates numerous UTXO-specific constructs such as Box, INPUTS, and OUTPUTS. A comprehensive list of these constructs can be found here.
  • A Box, essentially a UTXO, can accommodate up to ten registers for data storage. Analogous to Bitcoin, an Ergo transaction consumes one or more existing boxes (represented by the INPUTS array) and produces one or more new boxes (represented by the OUTPUTS array).
  • ErgoScript is not Turing complete, but it is possible to build Turing complete applications, as demonstrated in this peer-reviewed paper.

ErgoScript Syntax#

  • ErgoScript's syntax is a subset of Scala's. However, proficiency in Scala is not a prerequisite for learning ErgoScript. The Scala elements used in ErgoScript are minimal and straightforward, such as val. Unlike Java or Python, both Scala and ErgoScript access arrays using round parentheses. Hence, OUTPUTS(0) denotes the first element of the OUTPUTS array. In contrast to Scala, ErgoScript does not support the var keyword; all elements are immutable. ErgoScript, like Scala, supports functional programming, which simplifies interactions with collections using concepts such as foreach, exists, fold, etc.
  • An ErgoScript program, akin to ErgoTree, consists of a sequence of boolean predicates connected using && and ||.
  • ErgoScript provides cryptographic operations via BigInt and GroupElement (Elliptic curve point) types, along with associated operations like addition, multiplication, and exponentiation. It's important to note that BigInt operations in ErgoScript are performed modulo 2^256, unlike Scala, hence overflow needs to be carefully managed.