JSPM

  • Created
  • Published
  • Downloads 56
  • Score
    100M100P100Q57580F
  • License GPL-3.0

The Parity Promise-based API library for interfacing with Ethereum over RPC

Package Exports

  • @parity/api
  • @parity/api/util
  • @parity/api/util/decode

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@parity/api) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@parity/api

Parity.js is a thin, fast, Promise-based wrapper around the Ethereum APIs.

https://github.com/paritytech/js-api

installation

Install the package with npm install --save @parity/api

usage

initialisation

// import the actual Api class
import Api from '@parity/api';

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

making calls

perform a call

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

multiple promises

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

chaining promises

api.eth
  .newFilter({...})
  .then((filterId) => api.eth.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 = new 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 Ethcore JSON Ethereum RPC definitions. Mapping follows the naming conventions of the originals, i.e. eth_call becomes eth.call, personal_accounts becomes personal.accounts, etc.