How to use fluence - 6 common examples

To help you get started, we’ve selected a few fluence examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fluencelabs / fluence / fluence-js / src / examples / fluence-streamr / index.js View on Github external
import StreamrClient from 'streamr-client'
import * as fluence from "fluence"

const streamrClient = new StreamrClient();
const fluenceSession = fluence.directConnect("localhost", 29057);

const createTableQuery = "CREATE TABLE polution_uusimaa(id varchar(128), location varchar(128), parameter varchar(128), " +
    "value double, unit varchar(128), country varchar(128), city varchar(128), latitude double, " +
    "longitude double, local varchar(128), utc varchar(128))";

const deleteQuery = "DELETE FROM polution_uusimaa";

fluenceSession.invoke(deleteQuery).result().then((r) => console.log(r.asString()));

fluenceSession.invoke(createTableQuery)
    .result() // to return promise and wait for result we need to call `result()` function
    .then((r) => console.log(r.asString())); // `asString()` decodes bytes format to string

function insertQuery(data) {
    const query = `INSERT INTO polution_uusimaa VALUES ('${data.id}', '${data.location}', '${data.parameter}', ${data.value}, ` +
        `'${JSON.stringify(data.unit)}', '${data.country}', '${data.city}', ${data.latitude}, ${data.longitude}, '${data.local}', '${data.utc}')`;
github fluencelabs / fluence / fluence-js / src / examples / fluence-sqldb / index.ts View on Github external
async function preparePage() {
    let sessions = await fluence.connect(contractAddress, appId);

    let client = new DbClient(sessions);

    function updateStatus() {
        client.status().then((r) => {
            let addrs = client.appSession.workerSessions.map((s) => s.session.tm.addr);
            statusField.innerHTML = r.map((status, idx) => {
                let addr = addrs[idx];
                // if there is a response from a node
                if (isAvailable(status)) {
                    let info = status.workers[0];
                    if (info.WorkerRunning !== undefined) {
                        let runningInfo = info.WorkerRunning.info;
                        let status: Status = {
                            addr: addr,
                            block_hash: shorten(runningInfo.lastBlock as string, 10),
github fluencelabs / fluence / fluence-js / src / examples / todo-list / index.js View on Github external
// *****
// *** import `fluence` to start work with real-time cluster
// *****

import * as fluence from "fluence"

// *****
// *** create default session with credentials for interaction with the cluster,
// *** you can change the port if you want to interact with another node or your cluster have other ports
// *****

const session = fluence.directConnect("localhost", 25057);

window.onload = function () {

    //select elements and assign them to vars
    const newTask = document.querySelector('#new-task');
    const addTaskBtn = document.querySelector('#addTask');

    const toDoUl = document.querySelector(".todo-list ul");
    const completeUl = document.querySelector(".complete-list ul");

    const todoLoader = document.querySelector("#todo-loader");
    const doneLoader = document.querySelector("#done-loader");

    // *****
    // *** define table names that will store info about tasks
    // *****
github fluencelabs / fluence / dashboard / src / front / components / fluence-app-snippet / index.tsx View on Github external
};
        const iconEl = function (): HTMLElement {
            return window.document.getElementById(iconId) as HTMLElement;
        };
        const buttonEl = function (): HTMLButtonElement {
            return window.document.getElementById(buttonId) as HTMLButtonElement;
        };

        let session: AppSession;

        let auth = undefined;
        if (shortName.toLowerCase() === 'llamadb fork') {
            auth = llamaPrivateKey;
        }

        fluence.connect(defaultContractAddress, appId.toString(), fluenceNodeAddr, auth).then(s => {
            session = s;
            buttonEl().disabled = false;
            buttonEl().onclick = function (): any {
                if (inputField().value.trim().length !== 0) {
                    iconEl().style.display = 'inline-block';
                    buttonEl().disabled = true;
                    const queries = inputField().value.trim().split('\n').filter(s => {
                        return s.trim().length !== 0;
                    });
                    const results = queries.map(q => {
                        const res = session.request(q);

                        return res.then(r => {
                            return parser(r.asString().trim());
                        });
                    });
github fluencelabs / fluence / fluence-js / src / examples / fluence-sqldb / index.ts View on Github external
res.then((r: Result) => {
                if (fluence.isValue(r)) {
                    let strResult = Buffer.from(r.hex(), 'hex').toString();
                    console.log(`the result is:\n ${strResult}`);
                }
            });
            return res;
github fluencelabs / fluence / fluence-js / src / examples / fluence-sqldb / index.ts View on Github external
pr.then((r) => {
                    if (fluence.isValue(r)) {
                        let strRes = r.asString().replace('\\n', newLine);
                        resultField.value += sep + newLine + strRes + newLine + sep;
                    }
                });

fluence

the browser js-libp2p client for the Fluence network

Apache-2.0
Latest version published 3 years ago

Package Health Score

40 / 100
Full package analysis