Using Aqua Playground #
The Aqua Playground is a quick way to test out what is possible with Aqua and Fluence JS.
Running code on the Aqua Playground follows these steps:
- Write Aqua code that contains func and service definitions
- Write JS code that calls the functions and attaches callbacks to the services
- Hit Run to compile the Aqua code to JS
- The functions from the compiled Aqua are automatically imported and your JS uses those functions
- Special methods like appendOutput are made available to JS to provide output
Prerequisites #
The Fluence JS Tutorial provides a quick guide to the steps involved in creating a Fluence Application.
The Aqua Book describes the Aqua language.
Having these guides open when using the Aqua Playground will be worthwhile.
This guide describes how to use the Playground. For a development guide see Aqua Playground Github.
Writing Aqua #
The Aqua code is about definining services and functions. In the functions you can define which nodes different aspects of the code should run.
Here is a simple example:
import "@fluencelabs/aqua-lib/builtin.aqua"
service HelloWorld("hello-world"):
hello(str: string)
func sayHello() -> string:
HelloWorld.hello("Hello. Welcome to the Aqua Playground.")
func getRelayTime() -> u64:
on HOST_PEER_ID:
ts <- Peer.timestamp_ms()
<- ts
Compilation of Aqua to JS #
The compilation creates a JS file that the Aqua Playground automatically imports before running your entered JS.
In this JS file are two types of definition:
- For each service in Aqua, a JS function named registerServiceName is created. registerServiceName is called with an JS object containing callbacks that will be called when functions of the service are triggered.
- For each func in Aqua, an async JS function is created with the same name.
Writing JS #
There are a number of objects and functions exposed to the JS editor:
- The Fluence object
Fluence.getPeer().getStatus().peerId;
Fluence.getPeer().getStatus().relayPeerId;
- The krasnodar array of test node information
krasnodar[0].peerId
krasnodar[0].multiaddr
- The playgroundNodes array of currently connected node information
playgroundNodes[0].peerId
playgroundNodes[0].multiaddr
- Output helpers:
setOutput - Write to console (overwriting current text)
getOutput - Get current output as text
appendOutput - Append to current output text
Handling Errors #
Errors in compilation of Aqua or running of JS are displayed in the Output panel.