App3

Class

This’s main class of anything related APIS.

var App3 = require('app3js');

> App3.utils
> App3.version
> App3.providers
> App3.modules

App3.modules

Property of App3 class
App3.modules

Will return an object with the classes of all major sub modules, to be able to instantiate them manually.

Returns

Object: A list of modules:
  • Apis - Function: the Apis module for interacting with the APIS network see app3.apis for more.
  • Net - Function: the Net module for interacting with network properties see app3.apis.net for more.
  • Personal - Function: the Personal module for interacting with the APIS accounts see app3.apis.personal for more.

Example

App3.modules
> {
    Apis: Apis function(provider),
    Net: Net function(provider),
    Personal: Personal function(provider)
}

app3 object

The instance of App3

The app3js object is an umbrella package to house all APIS related modules.

var App3 = require('app3js');

var app3 = new App3('ws://some.local-or-remote.node:8546');

> app3.apis
> app3.utils
> app3.version

version

Property of App3 class and instance of App3
App3.version
app3.version

Contains the version of the app3 container object.

Returns

String: The current version.

Example

app3.version;
> "0.9.3-6"

utils

Property of App3 class and instance of App3
App3.utils
app3.utils

Utility functions are also exposes on the App3 class object directly.

See app3.utils for more.


setProvider

app3.setProvider(myProvider)
app3.apis.setProvider(myProvider)
...

Will change the provider for its module.

Note

When called on the umbrella package app3 it will also set the provider for all sub modules web3.apis, web3.shh, etc which needs a separate provider at all times.

Parameters

  1. Object - myProvider: a valid provider.

Returns

Boolean

Example

var App3 = require('app3js');

app3.setProvider('ws://localhost:8546');
// or
app3.setProvider(new App3.providers.WebsocketProvider('ws://localhost:8546'));

providers

app3.providers
app3.apis.providers
...

Contains the current available providers.

Value

Object with the following providers:

  • Object - WebsocketProvider: The Websocket provider is the standard for usage in legacy browsers.

Example

var App3 = require('app3');
var app3 = new App3('ws://remotenode.com:8546');
// or
var app3 = new App3(new App3.providers.WebsocketProvider('ws://remotenode.com:8546'));

givenProvider

app3.givenProvider
app3.apis.givenProvider
...

When using app3js in an APIS compatible browser, it will set with the current native provider by that browser. Will return the given provider by the (browser) environment, otherwise null.

Returns

Object: The given provider set or null;

Example


currentProvider

app3.currentProvider
app3.apis.currentProvider
...

Will return the current provider, otherwise null.

Returns

Object: The current provider set or null;

Example


BatchRequest

new app3.BatchRequest()
new app3.apis.BatchRequest()

Class to create and execute batch requests.

Parameters

none

Returns

Object: With the following methods:

  • add(request): To add a request object to the batch call.
  • execute(): Will execute the batch request.

Example

var contract = new app3.apis.Contract(abi, address);

var batch = new app3.BatchRequest();
batch.add(app3.apis.getBalance.request('0x0000000000000000000000000000000000000000', 'latest', callback));
batch.add(contract.methods.balance(address).call.request({from: '0x0000000000000000000000000000000000000000'}, callback2));
batch.execute();

extend

app3.extend(methods)
app3.apis.extend(methods)
...

Allows extending the app3 modules.

Note

You also have *.extend.formatters as additional formatter functions to be used for in and output formatting.

Parameters

  1. methods - Object: Extension object with array of methods description objects as follows:
    • property - String: (optional) The name of the property to add to the module. If no property is set it will be added to the module directly.
    • methods - Array: The array of method descriptions:
      • name - String: Name of the method to add.
      • call - String: The RPC method name.
      • params - Number: (optional) The number of parameters for that function. Default 0.
      • inputFormatter - Array: (optional) Array of inputformatter functions. Each array item responds to a function parameter, so if you want some parameters not to be formatted, add a null instead.
      • outputFormatter - ``Function: (optional) Can be used to format the output of the method.

Returns

Object: The extended module.

Example

app3.extend({
    property: 'myModule',
    methods: [{
        name: 'getBalance',
        call: 'apis_getBalance',
        params: 2,
        inputFormatter: [app3.extend.formatters.inputAddressFormatter, app3.extend.formatters.inputDefaultBlockNumberFormatter],
        outputFormatter: app3.utils.hexToNumberString
    },{
        name: 'getGasPriceSuperFunction',
        call: 'apis_gasPriceSuper',
        params: 2,
        inputFormatter: [null, app3.utils.numberToHex]
    }]
});

app3.extend({
    methods: [{
        name: 'directCall',
        call: 'apis_callForFun',
    }]
});

console.log(app3);
> App3 {
    myModule: {
        getBalance: function(){},
        getGasPriceSuperFunction: function(){}
    },
    directCall: function(){},
    ...
}