JSON dApp Environment (JDE)
Ergo Platform allows sophisticated dApps via smart contracts written in ErgoScript. Some notable examples are the SigmaUSD stable coin bank and ErgoMixer.
JSON dApp Environment (JDE) is another programming tool that you can use to interact with Ergo dApps. The differentiating feature of JDE is that its programming language is JSON.
This JDE is designed with the following goals in mind:
Enable tech-savvy users and developers to interact with existing (and future) Ergo dApps such as Sigma USD by programming the off-chain logic user-friendly.
Provide a "sandbox" mode, where users can send arbitrary scripts for execution such that the server does not have to worry about malicious programs. This enables the JDE service to be hosted remotely. An example is Kiosk-Web, where you can post arbitrary scripts (such as this, which gets the reserve coin rate) in "Tx Builder" and obtain results.
Goal #2 rules out many programming languages such as Java/Scala and Rust. This rules out all the so-called "Turing-complete" languages.
Let us take the use-case of purchasing, say, 10 Sigma-USD reserve coins as an example, which involves the following steps:
- Find the current oracle pool box and obtain the rate from register R4.
- Find the current bank box and obtain the relevant parameters (tokens in circulation and base reserves).
- Use the formulae to obtain the delta in base reserves.
- Compute the details of the new bank box to be created (nano-Ergs, tokens, registers)
- Compute the details of the new receipt box to be created (nano-Ergs, tokens, registers)
- Make a transaction creation request to the Ergo node with the above details.
All the above tasks can be programmed in JDE, as done in this script.
In general, JDE allows us to do the following:
- Find some boxes by address and/or box Id
- Extract values from those boxes (nanoErgs, registers and tokens), and define variables using those.
- Define constant values
- Perform computation using the constants and variables. JDE supports the if-then-else construct for control flow. However, it does not support loops.
- Define outputs using the values computed
- Make a transaction creation request to the Ergo node
How to use JDE
A compiled JAR is available on the release page. You can also generate the JAR yourself using the
sbt assembly command.
The following are the steps in using JDE.
- Understand the scripting language by looking at the sample scripts and the documentation.
- Ensure you have a fully synced Ergo node running.
- Write your script or edit the existing script for the task at hand.
- Invoke JDE via CLI to generate a transaction creation request (aka unsigned transaction) and some returned values.
Depending on your use case, you will be using the output of Step 4 differently.
- End users will use it to send a transaction on the Ergo blockchain
- Wallet authors will append some of their inputs/outputs before sending the transaction.
- dApp authors will use the returned values for further computation.
JDE also includes a web-service mode for the last two use-cases.
Please see the documentation for details.
- JDE is experimental. Please use with caution at your own risk. Always inspect the created transaction before sending it.
- If you discover a bug, please make an issue and a PR.
- If you find some feature missing, please make an issue.