0.6.7 • Published 5 years ago

scatterx v0.6.7

Weekly downloads
6
License
MIT
Repository
github
Last release
5 years ago

📦 scatterx

A npm package wrapping scatter-js to use easily.

Dependency

Scatter and npm or yarn

📃 Usage

🔧 setup

npm

npm install eosjs@16.0.9 scatterjs-plugin-eosjs // use scatterEOSX
npm install web3@1.0.0-beta.50 scatterjs-plugin-web3 // use scatterETHX
npm install scatterx

yarn

yarn add eosjs@16.0.9 scatterjs-plugin-eosjs // use scatterEOSX
yarn add web3@1.0.0-beta.50 scatterjs-plugin-web3 // use scatterETHX
yarn add scatterx

ScatterEOSX

ScatterEOSX is a wrapper for ScatterJS with ScatterEOS plugin.

setup

import { ScatterEOSX } from "scatterx";

// get networklist
let networkList = ScatterEOSX.networkList;
let network = networkList.kylin.asia; // For example, select kylin asia node.

// generate instance
let scatter = new ScatterEOSX(network, "YOUR_APPNAME");

send EOS

(async () => {
    // connect with scatter client and get identity and set user account to this instance.
    // Since the processing that has been completed is skipped inside the method, repeated execution of the login method does not cause much load.
    await scatter.login();

    // send eos to recipient
    // this example is sending 1.0000 EOS to hello account.
    await scatter.send("hello", 1, "memo");
})();

action

example1

(async () => {
    // set user account to this instance.
    // If you are already logged in, most of the processing of this method is skipped internally.
    await scatter.login();

    // send action
    // this action make hello contract execute hi action.
    const actObj = {
        contractName : "hello",
        actionName : "hi",
        params: ["bob"]
    };
    await scatter.action(actObj);
})();

example2

(async () => {
    await scatter.login();

    const actObj = {
        contractName: "devicemanage",
        actionName: "insert",
        params: ["youraccount1", "devicelabel", 1]
    };
    await scatter.action(actObj);
})();

"devicemanage" is my dapp.

transaction

example1

(async () => {
    await scatter.login();

    // this transaction include 2 actions and has linearizability.
    const actObj1 = {
        contractName : "hello",
        actionName : "hi",
        params: ["bob"]
    };

    const actObj2 = {
        contractName: "devicemanage",
        actionName: "insert",
        params: ["youraccount1", "devicelabel", 1]
    };

    // send transaction
    // If any action fails, all other actions also fail.
    await scatter.transaction(actObj1, actObj2);
})();

fetchTable

This method is not from scatter-js, but this method is useful.

(async () => {
    const query = {
            "code": "eosio.token",
            "scope": "eosio.token",
            "table": "accounts"
        };
    const response = await scatter.fetchTable(query);
})();

fetchTableMore

This method is used to fetch more than 100 data from the table.

Basically, it has the same arguments as fetchTable, BUT it is necessary to specify an id of uint64 type as the primary key.

(async () => {
    // This is one example, this query matches 205 rows (id 0 - 204) in kylinnet.
    const query = {
        "code": "pcscoreprtcl",
        "scope": "XTST",
        "table": "token",
        "limit": 100,
        "lower_bound": 103
    };
    const response = await scatter.fetchTableMore(query);
    console.log(response); // => (102) [{…}, {…}, {…}, {…}, {…}, …] (id 103 - 204)
})();

logout

(async () => {
    await scatter.logout();
})();

call eosjs's methods

Also, You can call eosjs method.

(async () => {
    await scatter.eosJS.METHOD_NAME(args);
})();

get network list

let networkList = ScatterEOSX.networkList;

setNetwork

This method is used to change network.

let laomao = ScatterEOSX.networkList.kylin.laomao;
scatter.setNetwork(laomao);

ScatterETHX

ScatterETHX is a wrapper for ScatterJS with ScatterETH plugin.

Sorry, this module doesn't work, probably due to a Scatter-side error.

others

Error

This npm package defines its own error type, ScatterError.

import { ScatterEOSX, ScatterError } from "scatterx";

let scatter = new ScatterEOSX(ScatterEOSX.networkList.kylin.asia, "YOUR_APPNAME");

// this try-catch block is in async function
try {
    await scatter.login();
    await scatter.action(actObj);
} catch (error) {
    if (error instanceof ScatterError) {
        ...
    }
}

✒️ Authors

Akihiro Otomo

Twitter Account: @akatsuki_py

0.6.7

5 years ago

0.6.6

5 years ago

0.6.4

5 years ago

0.6.3

5 years ago

0.6.2

5 years ago

0.6.1

5 years ago