HelloWorld. A Service interfaces functions executable on a peer. We will register a handler for this interface in our typescript application.
tellFortunecorrespondingly. These functions very simple. The only thing the first one does is calling the
HelloWorldservice located on the current peer. Similarly
getFortunemethod from the same service and returns the value to the caller. We will show you how to call these function from the typescript application.
aqua/hello-world.aquafile. You probably want to keep the generated TypeScript in the same directory with other typescript files, usually
src. Let's create the
src/_aquadirectory for that.
compile-aqua(1) runs the compilation once, producing
src/_aqua/hello-world.tsin our case
watch-aqua(2) starts watching for any changes in .aqua files recompiling them on the fly
Fluencefacade to start and stop the peer. The
startmethod accepts a parameters object which. The most common parameter is the address of the relay node the peer should connect to. In this example we are using the first node of the
krasnodarnetwork. If you do not specify the
connectTooptions will only be able to execute air on the local machine only. Please keep in mind that the init function is asynchronous.
service XXXdefinition in aqua code, the compiler provides a
registerXXXcounterpart. These functions provide a type-safe way of registering callback handlers for the services. The callbacks are executed when the appropriate service is called in aqua on the current peer. The handlers take form of the object where keys are the name of functions and the values are async functions used as the corresponding callbacks. For example in (4) we are registering handlers for
func XXXdefinition in aqua code, the compiler provides an async function which can be directly called from typescript. In (5, 6) we are calling exported aqua function with no arguments. Note that every function is asynchronous.
stopwhen the peer is no longer needed. As a rule of thumb all the peers should be uninitialized before destroying the application.
Hello, world!in the console.