{"id":27801430,"url":"https://github.com/ergoplatform/ergoscript-compiler","last_synced_at":"2026-01-06T12:56:22.608Z","repository":{"id":57733136,"uuid":"372159567","full_name":"ergoplatform/ergoscript-compiler","owner":"ergoplatform","description":null,"archived":false,"fork":false,"pushed_at":"2022-05-27T17:05:14.000Z","size":31,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2023-07-04T02:14:00.130Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ergoplatform.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-05-30T08:15:31.000Z","updated_at":"2023-07-04T02:14:00.131Z","dependencies_parsed_at":"2022-09-26T22:11:16.782Z","dependency_job_id":null,"html_url":"https://github.com/ergoplatform/ergoscript-compiler","commit_stats":null,"previous_names":[],"tags_count":1,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ergoplatform%2Fergoscript-compiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ergoplatform%2Fergoscript-compiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ergoplatform%2Fergoscript-compiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ergoplatform%2Fergoscript-compiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ergoplatform","download_url":"https://codeload.github.com/ergoplatform/ergoscript-compiler/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251825376,"owners_count":21649941,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-01T05:01:11.458Z","updated_at":"2026-01-06T12:56:22.583Z","avatar_url":"https://github.com/ergoplatform.png","language":"Scala","funding_links":[],"categories":["🛠️ Development Tooling \u003ca id=\"development-tooling\"\u003e\u003c/a\u003e"],"sub_categories":["📜 Smart Contracts \u0026 ErgoScript \u003ca id=\"smart-contracts--ergoscript\"\u003e\u003c/a\u003e"],"readme":"# ErgoScript Compiler\n\nA CLI tool for compiling ErgoScript code to an Ergo address.\n\n## How To Use\n\n1. Compile the ErgoScript compiler. If using the precompiled jar, skip to Step 2.\n    - Clone the repository using `git clone https://github.com/scalahub/ErgoScriptCompiler.git`.\n    - Ensure SBT is installed and set in path.\n    - Compile the jar using `sbt assembly` in the project root folder. \n \n      If everything goes well, a new JAR file will be created at the following path: \n      \n      `target/scala-2.12/ErgoScriptCompiler-assembly-0.1.jar`\n      \n      In the following, `\u003cjarFile\u003e` refers to the above JAR.\n\n2. Compile your ErgoScript code:\n    - Put your ErgoScript code in a text file named, say, `myScript.es` (the extension can be anything)\n    - Put any symbols (constants) in another file named, say, `mySymbols.json`. See below on how to write this file.\n    - The symbols file is optional and is needed only if your code references any symbols.\n    - Compile the file using `java -cp \u003cjarFile\u003e Compile \u003cergoScriptFile\u003e \u003coptionalSymbolsFile\u003e`. Examples:\n        - `java -cp ErgoScriptCompiler.jar Compile myScript.es mySymbols.json`\n        - `java -cp ErgoScriptCompiler.jar Compile myScript.es`\n\nSee the example below for a sample output.\n\n### Using in your own project\n\nAdd the following to build.sbt\n\n```\nlibraryDependencies += \"io.github.ergoplatform\" %% \"ergoscriptcompiler\" % \"1.0\"\n```\n\nThen use as: `util.Compiler.compile(ergoScriptFile: String,  symbolsFile: Option[String])`\n\n\n## Example \n\nThe folder [src/test/resources](src/test/resources) contains sample ErgoScript and symbol files.\nFollowing is a transcript of an execution.\n\n```bash\njava -cp \\\n      target/scala-2.12/ErgoScriptCompiler-assembly-0.1.jar \\\n      Compile \\\n      src/test/resources/AgeUSD.es \\\n      src/test/resources/AgeUSD_symbols.json \n      \nErgoTree:\n102b0400040004000e200fb1eca4646950743bc5a8c341c1...\n\nBlake2b256:\n2ffa0259301a5c7cdcf3074f7e5625f4764ca42453102804d4a774c6b39cc2e9\n\nAddress:\n29irJ65SHH5VxgQaXubC1z9eHzutUWV6BB2QGCbA9eQ53msb...\n\n```\n\nAs we can see, the program outputs three values:\n1. The ErgoTree corresponding to the Script, serialized and hex-encoded\n2. The Blake2b256 hash of the ErgoTree, hex encoded.\n3. The address corresponding to the ErgoTree.\n\n## Symbols File\n\nIf your ErgoScript code contains reference to a token ids or script hashes, then encode such values into a \"symbols\" file as follows (the extension can be anything):\n\n```json\n{\n  \"symbols\":[\n    {\n      \"name\":\"poolTokenId\",\n      \"type\":\"CollByte\",\n      \"value\":\"0fb1eca4646950743bc5a8c341c16871a0ad9b4077e3b276bf93855d51a042d1\"\n    },\n    {\n      \"name\":\"epochPrepScriptHash\",\n      \"type\":\"CollByte\",\n      \"value\":\"d998e06e0c093b0990fa3da4f3bea4364546803551ea9cac02623e9675ba4522\"\n    },\n    {\n      \"name\":\"buffer\",\n      \"type\":\"Int\",\n      \"value\":\"4\"\n    }\n  ]\n}\n```\n\nThe `type` can be any of `CollByte`, `Int`, `Long`, `GroupElement` and `Address`.\n\n- `CollByte` is simply given as a 32-byte long hex-encoded byte-array\n- `Int` and `Long` are given as numbers encoded as strings\n- `GroupElement` is given as a 33-byte compressed elliptic curve point, with point at infinity represented as all zeros.\n\n## Generating Payment Requests\n\nIn addition to compiling ErgoScript, this tool can also be used to generate a \"payment request\".\n\n- In the Ergo client's REST API, a payment request requires register values to be given as serialized-hex.\n- For instance, to store the integer 1, we would need to provide the register value as `0402`. \n  ```json\n  {\"address\": \"6Vs43...\", \"registers\": {\"R4\": \"0402\"}, \"amount\": 123}\n  ```\n- We can use this tool to generate the payment request from human-understandable values.\n\n- The syntax of the command is:\n  `java -cp \u003cjarFile\u003e Payment \u003chumanRequest.json\u003e \u003csymbolsFile.json\u003e`\n\n  Here the `humanRequest.json` is a payment request with the register value given as a name:\n\n  ```json\n  {\"address\": \"6Vs43...\", \"registers\": {\"R4\": \"myValue\"}, \"amount\": 123}\n  ```\n  The symbols file should contain the definition of `myValue`:\n  ```json\n  {\"name\": \"myValue\", \"type\": \"Int\", \"value\": \"1\"}\n  ```\n  The output is the final payment request with the names replaced with hex-serialized values.\n\nThe following shows an example transcript:\n```bash\njava -cp \\\n    target/scala-2.12/ErgoScriptCompiler-assembly-0.1.jar \\\n    Payment \\\n    src/test/resources/payment_request_AgeUSD.json \\\n    src/test/resources/payment_request_AgeUSD_symbols.json \n```\nOutput below:\n```json\n[ {\n  \"address\" : \"29irJ65SHH5VxgQaXubC1z9eHzutUWV6BB2QGCbA9eQ53...\",\n  \"value\" : 1000000,\n  \"assets\" : [ {\n    \"tokenId\" : \"a908bf2be7e199014b45e421dc4adb846d8de95e37da87c7f97ac6fb8e863fa2\",\n    \"amount\" : 10000000000000\n  }, {\n    \"tokenId\" : \"b240daba6b5f9f9b6d4e6d7fc8b7c0423f1dfa28a883ec626a18b69be6c7590e\",\n    \"amount\" : 10000000000000\n  }, {\n    \"tokenId\" : \"7bd873b8a886daa7a8bfacdad11d36aeee36c248aaf5779bcd8d41a13e4c1604\",\n    \"amount\" : 1\n  } ],\n  \"registers\" : {\n    \"R4\" : \"0500\",\n    \"R5\" : \"0500\"\n  }\n}, {\n  \"address\" : \"6Vs43fLottAzin3EiEiswbSD31ETscqBLy9i3zTWCwUVuG79...\",\n  \"value\" : 1000000,\n  \"assets\" : [ {\n    \"tokenId\" : \"77d14a018507949d1a88a631f76663e8e5101f57305dd5ebd319a41028d80456\",\n    \"amount\" : 1\n  } ],\n  \"registers\" : {\n    \"R4\" : \"0e0601a2b3c4d5e6\"\n  }\n} ]\n```\n\nThe resource folder contains a [sample payment request](src/test/resources/payment_request_AgeUSD.json) and a [sample symbols file](src/test/resources/payment_request_AgeUSD_symbols.json).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fergoplatform%2Fergoscript-compiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fergoplatform%2Fergoscript-compiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fergoplatform%2Fergoscript-compiler/lists"}