Rhai is an embedded scripting language for Rust (https://github.com/jonathandturner/rhai). Rhai Functions for Fluence allows you to execute Rhai functions and statements. The function can be defined in one call and it's results can be fetched from another call.
http://rhai-functions.surge.sh/ (Fluence App 402)
Assignment
let x = 58;
x
{"result":58}
Array
let x = [1, 2, 3];
x[1]
{"result":2}
Function
fn addme(a, b) {
a + b
}
addme(3, 4)
{"result":7}
if else
let a = true;
let x = 0;
if(a){
x = 50;
}
else{
x = 100;
}
x
{"result":50}
String
"hello " + "world!"
{"result":"hello world!"}
Predefined Function
factorial(5)
{"result":120}
-
Clone Repo
git clone https://github.com/viraja1/rhai_functions_fluence.git
-
Change directory
cd rhai_functions_fluence
-
Install Rust and Cargo
-
Generate wasm build
cargo +nightly build --lib --target wasm32-unknown-unknown --release
rhai_functions_fluence.wasm will be generated in target/wasm32-unknown-unknown/release
-
Deploy generated wasm file on Fluence
Deploy rhai_functions_fluence.wasm on Fluence and note down the App config shown in the bottom right part of the App console (contract, appId, ethereumUrl)
http://dash.fluence.network/deploy
-
Update Fluence app config
Update Fluence app config in client/src/components/config.js
vi client/src/components/config.js
-
Build client app
cd client npm install
-
Start client app
npm start
-
Open client app url in chrome
http://localhost:8080
-
Test the App