Fluence Network

The Fluence Labs Developer Hub

Welcome to the Fluence Labs developer hub. You'll find comprehensive guides and documentation to help you start working with Fluence Labs as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    API Reference

Javascript SDK

How to develop "backendless" apps with Fluence Javascript SDK

Fluence client library is designed to make it simple to send requests to the Fluence apps. You don't need to know anything about the internals of Fluence, just use it like other common libraries.

Installation

npm install --save fluence

Usage

We need to know three constants to work with Fluence:

// address to Fluence contract in Ethereum blockchain. 
let contractAddress = "0xeFF91455de6D4CF57C141bD8bF819E5f873c1A01";

// set ethUrl to `undefined` to use MetaMask instead of Ethereum node
let ethUrl = "http://geth.fluence.one:8545/";

// application to interact with that stored in Fluence contract
let appId = "43";

Let's create a session with Fluence and start sending requests.

import * as fluence from "fluence";

let session;

fluence.connect(contractAddress, appId, ethUrl).then((s) => {
    console.log("Session created");
    session = s;
});

You should remember that all interactions are asynchronous, so we always work with promises.

Send request to the backend:

let request = s.request("Hello, Fluence!")

Sending a request with transaction, and getting its result are separate operations, because result appears only after a few blocks, and can't be retrieved immediately. You may also not want to retrieve result for each operations, for performance reasons.

So, call result() to read result of the executed transaction:

request.result()
    .then((r) => console.log(r.asString()))

asString() method converts hex bytes to to a UTF-8 string.

That's all! Based on this API you can build lots of useful client-server applications.

Tips and Tricks

Sign all requests

You can add private key as a fourth argument in connect method if it is needed to check the correctness of signature on the side of a backend (authorization).

fluence.connect(contractAddress, appId, ethUrl, privateKey)

Use MetaMask

Just left ethUrl argument as undefined

fluence.connect(contractAddress, appId, undefined)

Direct connection for local testing

Use directConnect to connect to node that's running locally:

let appId = 41 // it is not important on local nodes, could be random number
fluence.directConnect("localhost", 30000, appId);

Debugging

For info on how to run a backend app locally for debugging, read here.


Javascript SDK


How to develop "backendless" apps with Fluence Javascript SDK

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.