openethereum/js/src/api
Gav Wood 3041c95408 Chain-selection from UI (#4859)
* First little bits for chain-selection.

* Provide RPCs and get settings through to user defaults.

* Hasty stash.

* Fix updater accidentally redownloading.

* Finish up.

* Add JS tests.

* Hypervisor should never run a binary modified before itself.

* Style.

* Help tweak.

* Fix test compile.

* Fix JS test

* Build fix for tests.

* Revert default chain name

* Another test

* Use spec name via client.

* Fix mock up.

* whitespace

[ci:skip]

* whitespace

[ci:skip]

* remove exit/restart endpoints.
2017-03-13 12:10:53 +01:00
..
contract Update Wallet to new Wallet Code (#4805) 2017-03-07 20:19:55 +01:00
format Fix TxViewer when no to (contract deployment) (#4847) 2017-03-10 10:08:16 +01:00
rpc Chain-selection from UI (#4859) 2017-03-13 12:10:53 +01:00
subscriptions Vault Management UI (first round) (#4446) 2017-02-20 16:40:01 +01:00
transport Signer provenance (#4477) 2017-02-14 22:45:43 +01:00
util Optimize signature for fallback function. (#4780) 2017-03-06 15:11:39 +01:00
api.js expose util as Api.util (#4372) 2017-01-31 17:25:42 +01:00
api.spec.js expose util as Api.util (#4372) 2017-01-31 17:25:42 +01:00
index.js Fix whitespace (#4299) 2017-01-25 18:51:41 +01:00
README.md Cleaning up polluted namespaces (#3143) 2016-11-06 12:51:53 +01:00

ethapi-js

A thin, fast, low-level Promise-based wrapper around the Ethereum APIs.

Build Status Coverage Status Dependency Status devDependency Status

contributing

Clone the repo and install dependencies via npm install. Tests can be executed via

  • npm run testOnce (100% covered unit tests)
  • npm run testE2E (E2E against a running RPC-enabled testnet Parity/Geth instance, parity --testnet and for WebScokets, geth --testnet --ws --wsorigins '*' --rpc)
  • setting the environment DEBUG=true will display the RPC POST bodies and responses on E2E tests

installation

Install the package with npm install --save ethapi-js from the npm registry ethapi-js

usage

initialisation

// import the actual EthApi class
import EthApi from 'ethapi-js';

// do the setup
const transport = new EthApi.Transport.Http('http://localhost:8545');  // or .Ws('ws://localhost:8546')
const ethapi = new EthApi(transport);

You will require native Promises and fetch support (latest browsers only), they can be utilised by

import 'isomorphic-fetch';

import es6Promise from 'es6-promise';
es6Promise.polyfill();

making calls

perform a call

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

multiple promises

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

chaining promises

ethapi.eth
  .newFilter({...})
  .then((filterId) => ethapi.eth.getFilterChanges(filterId))
  .then((changes) => {
    console.log(changes);
  });

contracts

attach contract

const abi = [{ name: 'callMe', inputs: [{ type: 'bool', ...}, { type: 'string', ...}]}, ...abi...];
const contract = new ethapi.newContract(abi);

deploy

contract
  .deploy('0xc0de', [params], 'superPassword')
  .then((address) => {
    console.log(`the contract was deployed at ${address}`);
  });

attach a contract at address

// via the constructor & .at function
const contract = api.newContract(abi).at('0xa9280...7347b');
// or on an already initialised contract
contract.at('0xa9280...7347b');
// perform calls here

find & call a function

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

parse events from transaction receipt

contract
  .parseTransactionEvents(txReceipt)
  .then((receipt) => {
    receipt.logs.forEach((log) => {
      console.log('log parameters', log.params);
    });
  });

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.

As a verification step, all exposed interfaces are tested for existing and pointing to the correct endpoints by using the generated interfaces from the above repo.