@susy-js/api

5.1.3 • Public • Published

@susy-js/api

Susy.js is a thin, fast, Promise-based wrapper around the Sophon APIs.

Build Status npm (scoped) npm dependencies Status

installation

Install the package with npm install --save @susy-js/api

usage

initialisation

// import the actual Api class
import Api from '@susy-js/api';

// do the setup
const provider = new Api.Provider.Http('http://localhost:8545');
const api = new Api(provider);

making calls

perform a call

api.sof.coinbase().then(coinbase => {
  console.log(`The coinbase is ${coinbase}`);
});

multiple promises

Promise.all([api.sof.coinbase(), api.net.listening()]).then(
  ([coinbase, listening]) => {
    // do stuff here
  }
);

chaining promises

api.sof
  .newFilter({...})
  .then((filterId) => api.sof.getFilterChanges(filterId))
  .then((changes) => {
    console.log(changes);
  });

contracts

attach contract

const abi = [{ name: 'callMe', inputs: [{ type: 'bool', ...}, { type: 'string', ...}]}, ...abi...];
const address = '0x123456...9abc';
const contract = api.newContract(abi, address);

find & call a function

contract.instance.callMe
  .call({ gas: 21000 }, [true, 'someString']) // or estimateGas or postTransaction
  .then(result => {
    console.log(`the result was ${result}`);
  });

apis

APIs implement the calls as exposed in the Sofcore JSON Sophon RPC definitions. Mapping follows the naming conventions of the originals, i.e. sof_call becomes sof.call, personal_accounts becomes personal.accounts, etc.

public node

For operation within a public node, the following peerDependencies needs to be added (this functionality will be moved shortly) -

Package Sidebar

Install

npm i @susy-js/api

Weekly Downloads

1

Version

5.1.3

License

MIT

Unpacked Size

380 kB

Total Files

127

Last publish

Collaborators

  • superstring