HelloWorldservice and host it on a peer-to-peer node of the Fluence testnet. In your IDE or terminal, change to the
2-hosted-servicesdirectory and open the
hellofunction which takes a string parameter and returns the
HelloWorldstruct consisting of the
replyfield, respectively. We can use the
build.shscript in the
./scripts/build.sh, to compile the code to the wasi32-wasm target from the VSCode terminal:
build.shscript gives the compile instructions with marine,
marine build --release, and copies the resulting Wasm module,
hello_world.wasm, to the
artifactsdirectory for easy access.
cargo test. However, we don't really care all that much about our native Rust functions being tested but want to test our WebAssembly functions. This is where the extra code in the test module comes into play. In short., we are running
cargo testagainst the exposed interfaces of the
hello_world.wasmmodule and in order to do that, we need the
marine_testmacro and provide it with both the modules directory, i.e., the
artifactsdirectory, and the location of the
Config.tomlfile. Note that the
Config.tomlfile specifies the module metadata and optional module linking data. Moreover, we need to call our Wasm functions from the module namespace, i.e.
hello_world.helloinstead of the standard
hello-- see lines 13 and 19 above, which we specify as an argument in the test function signature (lines 11 and 17, respectively).
cargo +nightly test --releasecommand. Please note that if
nightlyis your default, you don't need it in your
icommand and see that the interfaces we marked with the
marinemacro in our Rust code above are indeed exposed and available for consumption. Using the
callcommand, still in the REPL, we can access any available function in the module namespace, e.g.,
call hello_word hello [<string arg>]. You can exit the REPL with the
marineallows us to export the Wasm interfaces ready for use in Aqua. In your VSCode terminal, navigate to the `2-hosted-services` directory
marine aqua my_wasm.wasm >> my_aqua.aqua.
HelloWorldservice to the world by means of the Fluence peer-to-peer network. For this to happen, we need two things: the peer id of our target node(s) and a way to deploy the service. The latter can be accomplished with the
aquacommand line tool and with respect to the former, we can get a peer from one of the Fluence testnets with
aqua. In your VSCode terminal:
12D3KooWFEwNWcHqi9rtsmDhsYcDbRUCDXH84RC4FW6UfsFWaoHias our deployment target and deploy our service from the VSCode terminal.
secret key. Run:
<YOUR_SECRET_KEY>with the generated secret key and while in the