Skip to content

ErgoScript Compiler#

The ErgoScript Compiler is a Command Line Interface (CLI) tool designed to compile ErgoScript code into an Ergo address.

User Guide#

Setup and Compilation#

  1. If you're starting from source, compile the ErgoScript compiler using these steps:

    • Clone the repository by executing git clone
    • Make sure SBT is installed and correctly set up in your path.
    • Use the command sbt assembly in the project root folder to compile the JAR file.

    Upon successful compilation, a JAR file is generated in the following path: target/scala-2.12/ErgoScriptCompiler-assembly-0.1.jar. In the steps below, <jarFile> refers to this JAR.

    If you're using the precompiled JAR, proceed directly to the next step.

  2. Compiling ErgoScript code involves the following steps:

    • Save your ErgoScript code in a text file, for example, You can choose any file extension.
    • If your code references any symbols (constants), save them in a separate file, for instance, mySymbols.json. Refer to the section below on how to write this file.
    • This symbols file is optional and is only required if your code references any symbols.
    • Use the command java -cp <jarFile> Compile <ergoScriptFile> <optionalSymbolsFile> to compile the file. For example:
      • java -cp ErgoScriptCompiler.jar Compile mySymbols.json
      • java -cp ErgoScriptCompiler.jar Compile

Refer to the example below for a sample output.

Integration in Your Project#

To use ErgoScript Compiler in your project, add the following to your build.sbt:

libraryDependencies += "io.github.ergoplatform" %% "ergoscriptcompiler" % "1.0"

Then call: util.Compiler.compile(ergoScriptFile: String, symbolsFile: Option[String])

Examples and Outputs#

The src/test/resources directory contains sample ErgoScript and symbol files. Here's an example execution:

java -cp \
      target/scala-2.12/ErgoScriptCompiler-assembly-0.1.jar \
      Compile \
      src/test/resources/ \

The output includes: 1. The ErgoTree corresponding to the Script, serialized and hex-encoded. 2. The Blake2b256 hash of the ErgoTree, hex-encoded. 3. The address corresponding to the ErgoTree.

Symbol File Format#

If your ErgoScript code references token IDs or script hashes, encode such values in a "symbols" file as follows (any file extension is permissible):



Generating Payment Requests#

Apart from compiling ErgoScript, this tool can generate a "payment request". It replaces register values from human-understandable forms to serialized-hex needed by the Ergo client's REST API. For instance, to store the integer 1, you would provide the register value as 0402.

The command to generate payment requests is: java -cp <jarFile> Payment <humanRequest.json> <symbolsFile.json>