ethapi-js
A thin, fast, low-level Promise-based wrapper around the Ethereum APIs.
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; // do the setupconst transport = 'http://localhost:8545'; // or .Ws('ws://localhost:8546')const ethapi = transport;
You will require native Promises and fetch support (latest browsers only), they can be utilised by
; ;es6Promise;
making calls
perform a call
ethapieth ;
multiple promises
Promise all ethapieth ethapinet ;
chaining promises
ethapieth ;
contracts
attach contract
const abi = name: 'callMe' inputs: type: 'bool' ... type: 'string' ... ...abi...;const contract = ethapi abi;
deploy
contract ;
attach a contract at address
// via the constructor & .at functionconst contract = ethapi abi;// or on an already initialised contractcontract;// perform calls here
find & call a function
contractfunctions // or estimateGas or sendTransaction ;
parse events from transaction receipt
contract ;
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.