Module: rest

This is the main blockapps-rest interface.

Methods

(async, static) call(user, callArgs, options) → {Array|module:rest~TxResultWrapper}

Parameters:
Name Type Description
user module:rest~User

This must contain the token for the user

callArgs module:rest~CallArgs

This defines the method and the method arguments

options module:rest~Options

This identifies the options and configurations for this call

Returns:

If options.isAsync is set, this returns a transaction result object that contains the transaction hash. You can use resolveResult or resolveResults call to get the final results. If the options.isAsync is not set (default), it returns the result of the call as an array.

Type
Array | module:rest~TxResultWrapper
Example
// Consider the following contract
// contract SimpleStorage {
//   uint storedData;
//
//   function set(uint x) {
//       storedData = x;
//   }
//
//   function get() returns (uint) {
//       return storedData;
//   }
// }

const contractArgs = {
  name: "SimpleStorage",
  source: arraySrc,
  args: {} // Any constructor args would go here. We dont have any.
};
const contract = await rest.createContract(stratoUser, contractArgs, options);

const callArgs = {
  contract,
  method: "get",
  args: {}
};

const callResult = await rest.call(stratoUser, callArgs, options);

console.log(callResult);
// returns ['0' ...]

(async, static) callList(user, callListArgs, options) → {Array.<Array>|Array.<module:rest~TxResultWrapper>}

Parameters:
Name Type Description
user module:rest~User

This must contain the token for the user

callListArgs Array.<module:rest~CallArgs>

A list of function calls

options module:rest~Options

This identifies the options and configurations for this call

Returns:

If options.isAsync is set, this returns a list of transaction result objects that each contain the transaction hash. You can use resolveResult or resolveResults call to get the final results. If the options.isAsync is not set (default), it returns the results of transaction execution as a 2 dimensional array.

Type
Array.<Array> | Array.<module:rest~TxResultWrapper>
Example
// Consider the following contract
// contract SimpleStorage {
//   uint storedData;
//
//   function set(uint x) {
//       storedData = x;
//   }
//
//   function get() returns (uint) {
//       return storedData;
//   }
// }

const contractArgs = {
  name: "SimpleStorage",
  source: arraySrc,
  args: {} // Any constructor args would go here. We dont have any.
};
const contract = await rest.createContract(stratoUser, contractArgs, options);

const callArgs = {
  contract,
  method: "get",
  args: {}
};

const callResult = await rest.callList(stratoUser, [callArgs], options);

console.log(callResult);
// returns [ ['0' ...] ]

(async, static) compileContracts(user, contracts, options) → {Array.<module:rest~Contract>}

Parameters:
Name Type Description
user module:rest~User

This must contain the token for the user

contracts Array.<module:rest~Contract>

This contains a list of contracts to compile

options module:rest~Options

This identifies the options and configurations for this call

Returns:

Returns a list of contracts with the name and codeHash values populated

Type
Array.<module:rest~Contract>
Example
const contract = { name: "SimpleStorage", source: "...contract source" }
const result = await rest.compileContracts(
 stratoUser,
 [contract],
 options
);
// returns
// [ { contractName: 'SimpleStorage',
//     codeHash: '4552b102deb8f69bba4ca79847913c6878892787c0ff4592245452c00e324779' } ]

(async, static) createChain(user, chain, contract, options) → {module:rest~ChainHash}

Parameters:
Name Type Description
user module:rest~User

This must contain the token for the user

chain module:rest~Chain

This must be the object containing the arguments for the chain

contract module:rest~Contract

This must be the name of the contract

options module:rest~Options

This identifies the options and configurations for this call

Returns:

Hash of the newly created chain

Type
module:rest~ChainHash
Example
const createChainArgs = (uid, members) => {
 const contractName = `TestContract_${uid}`;
 const memberList = members.map(address => {
   return { address: address, enode };
 });
 const balanceList = members.map(address => {
   return { address: address, balance };
 });

 const chain = {
   label: `airline-${uid}`,
   src: `contract ${contractName} { }`,
   members: memberList,
   balances: balanceList,
   contractName
 };

 return { chain, contractName };

 };
 const uid = 5;
 const { chain, contractName: name } = createChainArgs(uid, [
   stratoUser.address
 ]);
const chainId = await rest.createChain(stratoUser, chain, contract, options);
// Returns
// "a72d6955662b1d2da4d338f8c87833592ebc490938308a42d3d528180ae55530"

(async, static) createContract(user, contract, options) → {module:rest~Contract|module:rest~TxResultWrapper}

Parameters:
Name Type Description
user module:rest~User

This must contain the token for the user

contract module:rest~Contract

This object describes the contract to upload

options module:rest~Options

This identifies the options and configurations for this call

Returns:

If options.async is set, it returns a transaction result object with the transaction. Final result can be obtained by using the resolveResult call. If options.async is not set (default), this call returns a contract with the name and address values populated

Type
module:rest~Contract | module:rest~TxResultWrapper
Example
const simpleStorageSrc = fsUtil.get("SimpleStorage.sol");
const contractArgs = {
  name: "SimpleStorage",
  source: simpleStorageSrc,
  args: {} // Any constructor args would go here. We dont have any.
};
const result = await rest.createContract(stratoUser, contractArgs, options);
// returns
// { name: 'SimpleStorage',
//   address: '5043751be046762926fc563fefb33e62919bf8b7' }

(async, static) createContractList(user, contracts, options) → {Array.<module:rest~Contract>|Array.<module:rest~TxResultWrapper>}

Parameters:
Name Type Description
user module:rest~User

This must contain the token for the user

contracts Array.<module:rest~Contract>

This is a list of contracts to upload

options module:rest~Options

This identifies the options and configurations for this call.

Returns:

If options.async is set, it returns a list of transaction result objects. Final results can be obtained by using the resolveResults call. If options.async is not set (default), this call returns a list of contracts with the name and address values populated

Type
Array.<module:rest~Contract> | Array.<module:rest~TxResultWrapper>
Example
const simpleStorageSrc = fsUtil.get("SimpleStorage.sol");
const contractArgs = {
  name: "SimpleStorage",
  source: simpleStorageSrc,
  args: {} // Any constructor args would go here. We dont have any.
};
const result = await rest.createContractList(stratoUser, [contractArgs], options);
// returns
// [{ bin:
//     '608060405234801561001057600080...6504300c1825957a56e0c10029',
//    chainId: null,
//    address: 'b728ad420aadd7082380e2024b935dd2898f6117',
//    'bin-runtime':
//     '6080604052600436106049576000357...6504300c1825957a56e0c10029',
//    codeHash:
//     { kind: 'EVM',
//       digest:
//        '4552b102deb8f69bba4ca79847913c6878892787c0ff4592245452c00e324779' },
//    name: 'SimpleStorage',
//    src:
//     'contract SimpleStorage {...}',
//    xabi:
//     { modifiers: {},
//       funcs: [Object],
//       kind: 'ContractKind',
//       types: [Object],
//       using: {},
//       constr: null,
//       events: {},
//       vars: [Object] } } ]

(async, static) createKey(user, options) → {String}

Parameters:
Name Type Description
user module:rest~User

This must contain the token for the user

options module:rest~Options

This identifies the options and configurations for this call.

Returns:

The address corresponding to the key pair for this user

Type
String
Example
// Initialize ba-rest oaut-utility
const oauth = oauthUtil.init(globalConfig.nodes[0].oauth);

// Get token using client-credential flow
const tokenResponse = await oauth.getAccessTokenByClientSecret();

// Extract token from token response
const oauthUser = { token: tokenResponse.token.access_token };

const key = await rest.createKey(oauthUser, options);
// Returns cdc7e277d9aecbce6aba5b9b16de815cadad3d2a

(async, static) createOrGetKey(user, options) → {String}

Parameters:
Name Type Description
user module:rest~User

This must contain the token for the user

options module:rest~Options

This identifies the options and configurations for this call.

Returns:

The address corresponding to the key pair for this user

Type
String
Example
// Initialize ba-rest oaut-utility
const oauth = oauthUtil.init(globalConfig.nodes[0].oauth);

// Get token using client-credential flow
const tokenResponse = await oauth.getAccessTokenByClientSecret();

// Extract token from token response
const oauthUser = { token: tokenResponse.token.access_token };

const key = await rest.createOrGetKey(oauthUser, options);
// Returns cdc7e277d9aecbce6aba5b9b16de815cadad3d2a

(async, static) createUser(user, options) → {module:rest~User}

Parameters:
Name Type Description
user module:rest~User

This must contain the token for the user

options module:rest~Options

This identifies the options and configurations for this call

Returns:
Type
module:rest~User
Example
var user = await rest.createUser({token: `${token}`}, options)
// returns a STRATO user
// { token: "eyJhbGc...ondq6g", address: "25eaa2879018122d7ba25fe4d9701ac367c44bf5"}

(async, static) getAccounts(user, options) → {Array.<module:rest~Account>}

Parameters:
Name Type Description
user module:rest~User

This identifies the user performing the query and contains the authentication token for the API call

options module:rest~Options

This identifies the options and configurations for this call

Returns:

A list of account details

Type
Array.<module:rest~Account>
Example
var accounts = await rest.getAccounts(user, {...options, query: {address: user.address}})
// returns a list of one account corresponding to the users' address
// [ { contractRoot:'56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
//     next: '/eth/v1.2/account?address=25eaa2879018122d7ba25fe4d9701ac367c44bf5&index=5',
//     kind: 'AddressStateRef',
//     balance: '2000000000000000000000',
//     address: '25eaa2879018122d7ba25fe4d9701ac367c44bf5',
//     latestBlockNum: 1,
//     codeHash:'c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470',
//     code: '',
//     nonce: 0 } ]

(async, static) getArray(user, contract, name, options) → {Array}

Parameters:
Name Type Description
user module:rest~User

This must contain the token for the user

contract module:rest~Contract

This object describes the contract to fetch state for. Minimally contains the address and the name of the contract

name String

This is the name of the array variable in the smart contract

options module:rest~Options

This identifies the options and configurations for this call

Returns:

Returns an array of values corresponding to the onchain state of the array variable named in the call

Type
Array
Example
// Consider the following contract
// contract DocArray {
//   uint256[] arr;
//
//   constructor() public {
//       arr = new uint256[](10);
//       for (uint256 i = 0; i < 10; i++) {
//           arr[i] = i + 1;
//       }
//   }
// }

const contractArgs = {
  name: "DocArray",
  source: arraySrc,
  args: {} // Any constructor args would go here. We dont have any.
};

const contract = await rest.createContract(stratoUser, contractArgs, options);

const array_state = await rest.getArray(stratoUser, contract, "arr", options);
// returns [ '1', '2', '3', '4', '5', '6', '7', '8', '9', '10' ]

(async, static) getChain(user, chainID, options) → {module:rest~ChainInfo}

Parameters:
Name Type Description
user module:rest~User

This must contain the token for the user

chainID module:rest~ChainHash

This must be the chainID of an existing private chain

options module:rest~Options

This identifies the options and configurations for this call

Returns:

Info about requested chain

Type
module:rest~ChainInfo
Example
const globalConfig = fsUtil.getYaml("config.yaml");
const options = { config: globalConfig, logger: console };
const queryOptions = {
  ...options,
  query: {}
};
const chainId = await rest.createChain(stratoUser, chain, contract, options);
const result = await rest.getChain(stratoUser, chainId, options);
// Returns
// { id:
//    'f99d95cf739bb7cc66fe16e352cd346def7d3c4b3f145f859072a2aae7119344',
//   info:
//    { balances: [ [Object], [Object] ],
//      members: [ [Object] ],
//      label: 'airline-2' } }

(async, static) getChains(user, chainIDs, options) → {Array.<module:rest~ChainInfo>}

Parameters:
Name Type Description
user module:rest~User

This must contain the token for the user

chainIDs Array.<module:rest~ChainHash>

This must be the array of chainIDs of existing private chains

options module:rest~Options

This identifies the options and configurations for this call

Returns:

Info about requested chain(s)

Type
Array.<module:rest~ChainInfo>
Example
const globalConfig = fsUtil.getYaml("config.yaml");
const options = { config: globalConfig, logger: console };
const queryOptions = {
  ...options,
  query: {}
};
const result = await rest.getChains(stratoUser, [], options);
// Returns
// [ { id:
//      'f99d95cf739bb7cc66fe16e352cd346def7d3c4b3f145f859072a2aae7119344',
//     info: { balances: [Array], members: [Array], label: 'airline-2' } },
//   { id:
//      'a72d6955662b1d2da4d338f8c87833592ebc490938308a42d3d528180ae55530',
//     info: { balances: [Array], members: [Array], label: 'airline-3' } },
//   { id:
//      '9f3a050a34faaab7d6d4c5c17bd70b0d1c2c9a6d40c1681323167fb43407bf18',
//     info: { balances: [Array], members: [Array], label: 'airline-5' } } ]

(async, static) getKey(user, options) → {String}

Parameters:
Name Type Description
user module:rest~User

This must contain the token for the user

options module:rest~Options

This identifies the options and configurations for this call.

Returns:
Type
String
Example
// Initialize ba-rest oaut-utility
const oauth = oauthUtil.init(globalConfig.nodes[0].oauth);

// Get token using client-credential flow
const tokenResponse = await oauth.getAccessTokenByClientSecret();

// Extract token from token response
const oauthUser = { token: tokenResponse.token.access_token };

const key = await rest.getKey(oauthUser, options);
// Returns cdc7e277d9aecbce6aba5b9b16de815cadad3d2a

(async, static) getState(user, contract, options) → {Object}

Parameters:
Name Type Description
user module:rest~User

This must contain the token for the user

contract module:rest~Contract

This object describes the contract to fetch state for. Minimally contains the address and the name of the contract

options module:rest~Options

This identifies the options and configurations for this call

Returns:

Returns an object with all accessible functions and state variables in this smart contract

Type
Object
Example
// Consider the following contract
// contract SimpleStorage {
//   uint storedData;
//
//   function set(uint x) {
//       storedData = x;
//   }
//
//   function get() returns (uint) {
//       return storedData;
//   }
// }

const contractArgs = {
  name: "SimpleStorage",
  source: arraySrc,
  args: {} // Any constructor args would go here. We dont have any.
};
const contract = await rest.createContract(stratoUser, contractArgs, options);
const state = await rest.getState(stratoUser, contract, options);
// returns
// { get: 'function () returns (uint)',
//   set: 'function (uint) returns ()',
//   storedData: '0' }

(async, static) pingOauth(user, options) → {String}

Parameters:
Name Type Description
user module:rest~User

This must contain the token for the user

options module:rest~Options

This identifies the options and configurations for this call

Returns:
Type
String
Example
const globalConfig = fsUtil.getYaml("config.yaml");
const options = { config: globalConfig, logger: console };
const queryOptions = {
  ...options,
  query: {}
};
const result = await rest.pingOauth(stratoUser, options);

// Returns
// 'success'

(async, static) resolveResult(user, pendingTxResult, options) → {module:rest~TxResultWrapper}

Parameters:
Name Type Description
user module:rest~User

This must contain the token for the user

pendingTxResult module:rest~TxResultWrapper

The tx result to resolve. Must contain the transaction hash.

options module:rest~Options

This identifies the options and configurations for this call

Returns:
Type
module:rest~TxResultWrapper
Example
const simpleStorageSrc = fsUtil.get("SimpleStorage.sol");
const contractArgs = {
  name: "SimpleStorage",
  source: simpleStorageSrc,
  args: {} // Any constructor args would go here. We dont have any.
};
const txResult = await rest.createContract(stratoUser, contractArgs, {
  ...options,
  isAsync: true
});
const result = await rest.resolveResult(stratoUser, txResult, options);
// Returns
// { status: 'Success',
// hash:
//  '3d25c575751bf4e9a502eef255dd5224f2b9585e339edc51fca02c33a45b177d',
// txResult:
//  { deletedStorage: '',
//    contractsDeleted: '',
//    gasUsed: '13955',
//    stateDiff: '',
//    time: 0.000694605,
//    kind: 'EVM',
//    chainId: null,
//    response:
//     '608060405260043...a6504300c1825957a56e0c10029',
//    blockHash:
//     '82bb60c456661c8e05caa36b227be8e717bf2b7c7ae0de30fcd7b295d731be9b',
//    transactionHash:
//     '3d25c575751bf4e9a502eef255dd5224f2b9585e339edc51fca02c33a45b177d',
//    etherUsed: '13955',
//    newStorage: '',
//    message: 'Success!',
//    trace: '',
//    contractsCreated: 'bf68d882d8e95d94926379538ccab45932e26c03' },
// data:
//  { tag: 'Upload',
//    contents:
//     { bin: 'bin removed.',
//       chainId: null,
//       address: 'bf68d882d8e95d94926379538ccab45932e26c03',
//       'bin-runtime': 'bin-runtime removed.',
//       codeHash: [Object],
//       name: 'SimpleStorage',
//       src: 'source removed.',
//       xabi: 'xabi removed.' },
//    src: 'source removed.' } }

(async, static) resolveResults(user, pendingTxResults, options) → {Array.<module:rest~TxResultWrapper>}

Parameters:
Name Type Description
user module:rest~User

This must contain the token for the user

pendingTxResults Array.<module:rest~TxResultWrapper>

The tx results to resolve. Must contain the transaction hash.

options module:rest~Options

This identifies the options and configurations for this call

Returns:
Type
Array.<module:rest~TxResultWrapper>
Example
const simpleStorageSrc = fsUtil.get("SimpleStorage.sol");
const contractArgs = {
  name: "SimpleStorage",
  source: simpleStorageSrc,
  args: {} // Any constructor args would go here. We dont have any.
};
const txResults = await rest.createContractList(stratoUser, [contractArgs], {
  ...options,
  isAsync: true
});
const results = await rest.resolveResults(stratoUser, txResults, options);
// Returns
// [{ status: 'Success',
// hash:
//  '3d25c575751bf4e9a502eef255dd5224f2b9585e339edc51fca02c33a45b177d',
// txResult:
//  { deletedStorage: '',
//    contractsDeleted: '',
//    gasUsed: '13955',
//    stateDiff: '',
//    time: 0.000694605,
//    kind: 'EVM',
//    chainId: null,
//    response:
//     '608060405260043...a6504300c1825957a56e0c10029',
//    blockHash:
//     '82bb60c456661c8e05caa36b227be8e717bf2b7c7ae0de30fcd7b295d731be9b',
//    transactionHash:
//     '3d25c575751bf4e9a502eef255dd5224f2b9585e339edc51fca02c33a45b177d',
//    etherUsed: '13955',
//    newStorage: '',
//    message: 'Success!',
//    trace: '',
//    contractsCreated: 'bf68d882d8e95d94926379538ccab45932e26c03' },
// data:
//  { tag: 'Upload',
//    contents:
//     { bin: 'bin removed.',
//       chainId: null,
//       address: 'bf68d882d8e95d94926379538ccab45932e26c03',
//       'bin-runtime': 'bin-runtime removed.',
//       codeHash: [Object],
//       name: 'SimpleStorage',
//       src: 'source removed.',
//       xabi: 'xabi removed.' },
//    src: 'source removed.' } }]

(async, static) search(user, contracts, options) → {Object}

Parameters:
Name Type Description
user module:rest~User

This must contain the token for the user

contracts module:rest~Contract

This the contract to search for

options module:rest~Options

This identifies the options and configurations for this call

Returns:

If options.async is set, only the hashes are populated, otherwise all the field are populated

Type
Object
Example
const globalConfig = fsUtil.getYaml("config.yaml");
const options = { config: globalConfig, logger: console };
const queryOptions = {
  ...options,
  query: {}
};
const searchResults = await rest.search(
 stratoUser,
 { name: "SimpleStorage" },
 queryOptions
);
// Returns
// [ { address: '2793d0f3afc31720ef18f6736073154e9131b21e',
//     chainId: '',
//     block_hash:
//      '5f306c319d9493fa77d14516e6fa12accc9e6a1b31b3e32ea016270e529b5cda',
//     block_timestamp: '2020-08-04 15:59:20 UTC',
//     block_number: '5',
//     transaction_hash:
//      '3e6ed2346d35c38c2c87c9cdb5603d914998886e7110675db840ff870fe55784',
//     transaction_sender: '28aced430a5121bbc8613e8415583c47cb9a4516',
//     transaction_function_name: '',
//     storedData: 10 } ]

(async, static) searchUntil(user, contract, predicate, options) → {Object}

Parameters:
Name Type Description
user module:rest~User

This must contain the token for the user

contract module:rest~Contract

This the contract to search for

predicate Object

This identifies the predicate that determines when to stop the search

options module:rest~Options

This identifies the options and configurations for this call

Returns:

If options.async is set, only the hashes are populated, otherwise all the field are populated

Type
Object
Example
const globalConfig = fsUtil.getYaml("config.yaml");
const options = { config: globalConfig, logger: console };
const queryOptions = {
  ...options,
  query: {}
};
// predicate is created: to wait until response is available otherwise throws the error
function predicate(data) {};
const result = await rest.searchUntil(stratoUser, {name: "SimpleStorage"}, predicate, queryOptions);
// Returns
// [ { address: '60fb089dc62858df014819d618aa3f43391ddb9c',
//     chainId: '',
//     block_hash:
//      'fb7edc20a2678ca60024f81d926d1637eb418012beae2fedb7e7c4250406ea82',
//     block_timestamp: '2020-08-04 20:48:18 UTC',
//     block_number: '3',
//     transaction_hash:
//      '32321367696882da2feb9483fa31346f68abf77cc1a01ace6ef5a2b774bc8d38',
//     transaction_sender: '594f19ad4a55d6434711a51f628f22abf4afc55a',
//     transaction_function_name: '',
//     storedData: 10 } ]

(async, static) searchWithContentRange(user, contract, options) → {Object}

Parameters:
Name Type Description
user module:rest~User

This must contain the token for the user

contract module:rest~Contract

This the contract to search for

options module:rest~Options

This identifies the options and configurations for this call

Returns:

If options.async is set, only the hashes are populated, otherwise all the field are populated

Type
Object
Example
const globalConfig = fsUtil.getYaml("config.yaml");
const options = { config: globalConfig, logger: console };
const queryOptions = {
  ...options,
  query: {}
};
const result = await rest.searchWithContentRange(stratoUser, { name: "SimpleStorage" }, queryOptions);
// Returns
// { data:
//    [ { address: '1db4cdb5051bceb5fd0cfa8f186472bd47b5a29e',
//        chainId: '',
//        block_hash:
//         '202f910a94fe10b5f0e2fa1ab40cfad94dada3d5cd38a46255bfbb168d7f2229',
//        block_timestamp: '2020-08-06 14:41:05 UTC',
//        block_number: '2',
//        transaction_hash:
//         '5cdeb87bdcce330b0c4c69bc78b1320773374c0db6423abc4806f43f545a14ca',
//        transaction_sender: 'd7b9e349d779247462aedfce35cdaf9b1eb495dc',
//        transaction_function_name: '',
//        storedData: 0 } ],
//   contentRange: { start: 0, end: 0, count: 1 } }

(async, static) searchWithContentRangeUntil(user, contract, predicate, options) → {Array.<module:rest~TxResultWrapper>}

Parameters:
Name Type Description
user module:rest~User

This must contain the token for the user

contract module:rest~Contract

This the contract to search for

predicate Object

This identifies the predicate that determines when to stop the search

options module:rest~Options

This identifies the options and configurations for this call

Returns:

If options.async is set, only the hashes are populated, otherwise all the field are populated

Type
Array.<module:rest~TxResultWrapper>
Example
const globalConfig = fsUtil.getYaml("config.yaml");
const options = { config: globalConfig, logger: console };
const queryOptions = {
  ...options,
  query: {}
};
// predicate is created: to wait until response is available otherwise throws the error
function predicate(response) {
 return response.data.length >= 4;
}
const result = await rest.searchWithContentRangeUntil(stratoUser, contracts[0], predicate, queryOptions);
// Returns
// { data:
//    [ { address: '07c9cb29ac43fe2257143074fb344203accb53eb',
//        chainId: '',
//        block_hash:
//         '0e39030b10d80e5abaaf90a4b2d2322644fbb7b3b5cc0c8ea52a95d91adcd4ff',
//        block_timestamp: '2020-08-05 16:49:28 UTC',
//        block_number: '2',
//        transaction_hash:
//         '8c05b2ad6e8759122856c00f0646793073e0982d64ebd30ab3fb55a33da5cecf',
//        transaction_sender: 'ebc383a8d64c07b3f472da8612bb463cf338c0b4',
//        transaction_function_name: '',
//        intValue: 2000,
//        stringValue: '_2000_' },
//      { address: '64560dd4c8789663303e97937f732976d98dab95',
//        chainId: '',
//        block_hash:
//         '6840a306239c9f0e31359f9950a12e2a3595690273d38ce52bae970e26cd80e6',
//        block_timestamp: '2020-08-05 16:49:29 UTC',
//        block_number: '3',
//        transaction_hash:
//         '07e8b895559737c76e5323d3b2f1e6c893a91d68eb6fa08c6fb461133c37e4ad',
//        transaction_sender: 'ebc383a8d64c07b3f472da8612bb463cf338c0b4',
//        transaction_function_name: '',
//        intValue: 2001,
//        stringValue: '_2001_' },
//      { address: '9f7f1f4a6479463145bab645b64acecc230f9332',
//        chainId: '',
//        block_hash:
//         '50c25b7e693904b545bc7b9003c0eb57a6149d0bd42f12aac72962e01ae8588a',
//        block_timestamp: '2020-08-05 16:49:30 UTC',
//        block_number: '4',
//        transaction_hash:
//         '3a5e19730a8f32d71a707c78349c418375010d3ff98c74aa0f9156477ba98822',
//        transaction_sender: 'ebc383a8d64c07b3f472da8612bb463cf338c0b4',
//        transaction_function_name: '',
//        intValue: 2002,
//        stringValue: '_2002_' },
//      { address: 'c1307553863b1a932f2a5d994926b64ecedc890e',
//        chainId: '',
//        block_hash:
//         '1e674f96f42c08897d51ede082c95756493c26deb552588f854c44aa6f5adc4a',
//        block_timestamp: '2020-08-05 16:49:31 UTC',
//        block_number: '5',
//        transaction_hash:
//         'f93499e6e003d993ea5b2bf38d581da7e988a61c6a4077ebf60a242782e95b9c',
//        transaction_sender: 'ebc383a8d64c07b3f472da8612bb463cf338c0b4',
//        transaction_function_name: '',
//        intValue: 2003,
//        stringValue: '_2003_' } ],
//   contentRange: { start: 0, end: 3, count: 4 } }

(async, static) send(user, sendTx, options) → {module:rest~TxResultWrapper}

Parameters:
Name Type Description
user module:rest~User

This must contain the token for the user

sendTx module:rest~SendArgs

This describes the recipient, amount of tokens and the chain id (optional) for the token transfer

options module:rest~Options

This identifies the options and configurations for this call

Returns:

If options.async is set, only the hashes are populated, otherwise all the field are populated

Type
module:rest~TxResultWrapper
Example
const sendArgs = {
  toAddress: "cdc7e277d9aecbce6aba5b9b16de815cadad3d2b",
  value: 100000000
};

const result = await rest.send(stratoUser, sendArgs, options);
// Returns
// { hash:
//  '168f76ccf50582953d2fc9cbdc3bb60bd777562662dd9a2330ef29edab282a5c',
// gasLimit: 32100000000,
// codeOrData: '',
// chainId: null,
// gasPrice: 1,
// to: 'cdc7e277d9aecbce6aba5b9b16de815cadad3d2b',
// value: '100000000',
// from: 'cdc7e277d9aecbce6aba5b9b16de815cadad3d2a',
// r:
//  'a657713d295f159566fd1a8618cc12931e965b0f9a509a7125d2572fba73a3c1',
// metadata: null,
// s:
//  'c46bf8706053e9809064bd8d0f89c6ac0c963bc4b274a31cf8922ff9db858fd',
// v: '1b',
// nonce: 19,
// src: 'source removed.',
// bin: 'bin removed.',
// 'bin-runtime': 'bin-runtime removed.',
// xabi: 'xabi removed.' }

(async, static) sendMany(user, sendTx, options) → {Array.<module:rest~TxResultWrapper>}

Parameters:
Name Type Description
user module:rest~User

This must contain the token for the user

sendTx Array.<module:rest~SendArgs>

This describes the recipient, amount of tokens and the chain id (optional) for the token transfer

options module:rest~Options

This identifies the options and configurations for this call

Returns:

If options.async is set, only the hashes are populated, otherwise all the field are populated

Type
Array.<module:rest~TxResultWrapper>
Example
const sendArgs = {
  toAddress: "cdc7e277d9aecbce6aba5b9b16de815cadad3d2b",
  value: 100000000
};

const result = await rest.send(stratoUser, [sendArgs], options);
// Returns
// [{ hash:
//  '168f76ccf50582953d2fc9cbdc3bb60bd777562662dd9a2330ef29edab282a5c',
// gasLimit: 32100000000,
// codeOrData: '',
// chainId: null,
// gasPrice: 1,
// to: 'cdc7e277d9aecbce6aba5b9b16de815cadad3d2b',
// value: '100000000',
// from: 'cdc7e277d9aecbce6aba5b9b16de815cadad3d2a',
// r:
//  'a657713d295f159566fd1a8618cc12931e965b0f9a509a7125d2572fba73a3c1',
// metadata: null,
// s:
//  'c46bf8706053e9809064bd8d0f89c6ac0c963bc4b274a31cf8922ff9db858fd',
// v: '1b',
// nonce: 19,
// src: 'source removed.',
// bin: 'bin removed.',
// 'bin-runtime': 'bin-runtime removed.',
// xabi: 'xabi removed.' }]

(async, static) waitForAddress(user, contract, options) → {Object}

Parameters:
Name Type Description
user module:rest~User

This must contain the token for the user

contract module:rest~Contract

This must be the name of the contract

options module:rest~Options

This identifies the options and configurations for this call

Returns:

Returns an object with information including the address, given a contract

Type
Object
Example
const globalConfig = fsUtil.getYaml("config.yaml");
const options = { config: globalConfig, logger: console };
const queryOptions = {
  ...options,
  query: {}
};
const result = await rest.waitForAddress(stratoUser, contract, queryOptions);

// Returns
// { address: '2b755e392056c9b58f4f71da7ea8f47f553dd50b',
//   chainId: '',
//   block_hash:
//    '4cd55ea1189677fc32be1b4bbd9f93d75c81610c7bafb4f09964197a6b3096fa',
//   block_timestamp: '2020-08-12 16:14:16 UTC',
//   block_number: '2',
//   transaction_hash:
//    'f67484a3c5b9a1c57a66d843ee8e9dc72280336f6dccd8ec798873a64fb61f2d',
//   transaction_sender: 'b311acca558955c4b6296306f0e4a7ee0eb8f13d',
//   transaction_function_name: '',
//   storedData: 0 }

Type Definitions

Account

This object defines a STRATO account

Type:
  • Object
Properties:
Name Type Description
kind String

Account type

balance String

Eth balance in wei

address String

Account address

latestBlockNum Number

Last block number in which the state for this account was changed

codeHash String

Code hash. Relevant if this is a contract account

nonce: Number

Account nonce

CallArgs

This object defines a function call to a STRATO smart contract

Type:
  • Object
Properties:
Name Type Description
contract module:rest~Contract

Defines the contract on which to call the method. Should contain name and address.

method String

Name of the method to call

args Object

Arguments for the method call

value: Number

Optional. Number of tokens to send to the smart contract

chainid: String

Optional chain id of the private chain if the contract is being called on a private chain

txParams: module:rest~TxParams

Optional. Defines gas limit and gas price for transaction execution

Chain

The object containing arguments of a chain

Type:
  • Object
Properties:
Name Type Description
label String

The name of the chain

src String

Source contract

memberList Array

Array containing the members of the chain

balanceList Array

Array containng the balances of each member of the chain

ChainHash

The hash of a chain

Type:
  • Object
Properties:
Name Type Description
hash String

The hash of a chain

ChainInfo

Info about a chain such as members/balances/etc.

Type:
  • Object
Properties:
Name Type Description
balances Array.<Object>

Balances existing within the chain

members Array.<Object>

Members of the chain

label String

Name of the chain

CodeHash

This object defines the codeHash and the vm type in an uploaded contract object

Type:
  • Object
Properties:
Name Type Description
kind String

This is the type of VM used. Is either SolidVM or EVM

digest String

This is the code hash

Config

This contains node configuration information

Type:
  • Object
Properties:
Name Type Description
VM String

This identifies the type of VM to use. It must equal one of EVM or SolidVM

apiDebug Boolean

This flag enables debug output to be sent to the logger

nodes Array.<module:rest~Node>

This contains a collection of STRATO nodes which are being used. It must have atleast one member

timeout Number

Length of time to wait before giving up on a request in milliseconds

Contract

This object defines a STRATO smart contract

Type:
  • Object
Properties:
Name Type Description
name String

Name of the smart contract

source String

Source code for the smart contract

args Object

Optional arguments for the smart contract constructor

codeHash: String

Contract code hash. Not required. Populated by the compileContract call.

address: String

Contract address. Not required. Populated by uploading a contract to STRATO.

Node

This identifies a STRATO node and contains OAuth discovery urls to authenticate to this node.

Type:
  • Object
Properties:
Name Type Description
id Number

Node identifier

url String

The base url of the node of the form {PROTOCOL}://{HOST}:{PORT}

publicKey String

This is the public key of the node. Used to verify the identify of the node.

port Number

This is the port number of the STRATO process on this node. Usually equals 30303

oauth module:rest~OAuthConfig

This describes the oauth configuration of a STRATO node

OAuthConfig

This object describes the oauth configuration of a STRATO node

Type:
  • Object
Properties:
Name Type Description
appTokenCookieName String

Specifies the HTTP only cookie name. Used to identify authentication cookie if cookies are used instead of headers

scope String

Identifies OAuth scope

appTokenCookieMaxAge Number

Used to set auth cookie expiration

clientId String

OAuth client id for client credential and auth code grant flows

clientSecret String

OAuth client secret corresponding to the clientId

openIdDiscoveryUrl String

Discovery url for OAuth

redirectUri String

OAuth callback url for auth code grant flow

logoutRedirectUri String

Redirect URI to redirect user after a successful logout

Options

This object defines options, configurations and metadata for the STRATO node

Type:
  • Object
Properties:
Name Type Description
config Config

This contains node identifiers, configuration and metadata options for this call.

logger Object

This is a logger interface. It uses the console by default but can be set to custom logger like winston.

headers Object

This allows adding custom HTTP headers for requests to STRATO

query Object

This allows adding custom HTTP query params to requests. Useful for searching contracts

history Array.<String>

This allows us to specify contract names for which to track history when uploading smart contract source code

noindex Array.<String>

This allows us to specify contract names for which to skip relational indexing when uploading smart contract source code

isAsync Boolean

If set, the call returns a transaction hash instead of waiting for a transaction confirmation. Default value is false.

SendArgs

This object defines the shape of a request for transfer tokens

Type:
  • Object
Properties:
Name Type Description
toAddress String

Address of the receiver

value Number

amount of tokens to transfer in wei

txParams: module:rest~TxParams

Optional. Defines gas limit and gas price for transaction execution

chainid: String

Optional chain id of the private chain if the transfer is being executed on a private chain

TxData

This is the formatted output of a transaction execution

Type:
  • Object
Properties:
Name Type Description
Tag String

This identified the type of the transaction. Is one of Call, Upload or Send

contents Array | module:rest~UploadedContract

This is the formatted output of executing the transaction

TxParams

This object defines transaction specific options for STRATO. There should be no need to change the defaults for most use cases.

Type:
  • Object
Properties:
Name Type Description
gasLimit Number

This is the upper limit for the amount of gas this transaction should consume. Defaults to 32100000000 wei

gasPrice Number

This is the price of gas the user is willing to pay. Defaults to 1 wei

TxResult

The result of submitting a transaction to STRATO.

Type:
  • Object
Properties:
Name Type Description
contractsDeleted String

Comma separated list of contract addresses that were deleted as a result of executing this transaction

gasUsed String

Amount of gas used by this transaction in hexadecimal

stateDiff String
time String

Amount of time the VM took to execute this tramsaction

kind String

Type of VM used to execute this transaction. SolidVM or EVM

chainid String

Chain id (present if transaction was executed on a private chain)

response String

Raw output of executing transaction

blockHash String

Block hash of the block in which this transaction was finalized

transactionHash String

Transaction hash

etherUsed String

Amount of ether used to execute this transaction (gasUsed * gasPrice)

contractsCreated String

Comma separated list of contract addresses created as a result of executing this transaction

TxResultWrapper

The result of submitting a transaction to STRATO.

Type:
  • Object
Properties:
Name Type Description
status String

Status of the transaction. One of Pending, Success or Failure.

hash String

Transaction hash

txResult module:rest~TxResult

Result of the execution of the transaction

data module:rest~TxData

Data returned by the execution of a STRATO transaction

UploadedContract

This object describes the result of uploading one contract in a list of smart contracts being uploaded to STRATO

Type:
  • Object
Properties:
Name Type Description
name String

Name of the smart contract

chainId String

Chain identifier if the smart contract is being uploaded to a private chain. This property is null for main chain smart contracts

address: String

Contract address. Not required. Populated by uploading a contract to STRATO.

codeHash: module:rest~CodeHash

Describes the codehash and the VM used to generate the code hash

bin: String

The compiled Solidity byte code

xabi: Object

An object defining the contract metadata

User

This identifies a user

Type:
  • Object
Properties:
Name Type Description
token String

This is the OAuth JWT corresponding to this user. STRATO uses the JWT to identify the user and unlock the user's private key to sign transactions. The token must be present in most cases.

address String

This is the address corresponding to the user's private key. This is an optional parameter.