70f87ea002
* Skeleton packages * Publish parity.js package to npm * [ci skip] js-precompiled 20161029-190427 * Extra step information * [ci skip] js-precompiled 20161029-192209 * Use autToken for npmjs (cannot run headless in docker) * [ci skip] js-precompiled 20161029-193414 * Correct package.json structure * [ci skip] js-precompiled 20161029-194003 * Scope package to public * [ci skip] js-precompiled 20161029-194529 * Start package version at 0.1.0 * Build proper umd library * [ci skip] js-precompiled 20161029-231233 * Update build/release stage * [ci skip] js-precompiled 20161030-071454 * Basic README.md to satisfy npmjs * [ci skip] js-precompiled 20161030-073150 * CommonJs format * [ci skip] js-precompiled 20161030-075034 * Update README.md * update dependencies * [ci skip] js-precompiled 20161030-075727 * Starting package version * Build only on master
1.6 KiB
1.6 KiB
parity.js
Parity.js is a thin, fast, Promise-based wrapper around the Ethereum APIs.
installation
Install the package with npm install --save @parity/parity.js
usage
initialisation
// import the actual Api class
import { Api } from '@parity/parity.js';
// do the setup
const transport = new Api.Transport.Http('http://localhost:8545');
const api = new Api(transport);
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.