loom-js
NodeJS & browser client for Loom DAppChains.
Last updated a year ago by loomx .
BSD-3-Clause · Original npm · Tarball · package.json
$ cnpm install loom-js 
SYNC missed versions from official npm registry.

Loom.js Build Status

JS library for building browser apps & NodeJS services that interact with Loom DAppChains.

Install

NodeJS

# NPM
npm install loom-js
# Yarn
yarn add loom-js

Browser

<script src="https://cdn.jsdelivr.net/npm/loom-js@1.15.0/dist/loom.umd.js"></script>

Debugging

loom-js uses the debug package for logging.

  • To inspect the logs when running in the browser set localStorage.debug = '*'
  • To inspect the logs when running in NodeJS set the DEBUG env var to *

See docs for debug package if you wish to filter the log messages.

Development

# build for Node
yarn build
# build for Browser
yarn build:browser
# build for Node while targeting ES2017 (more readable than ES5)
yarn build:dev
# run unit tests on Node & Browser
yarn test
# auto-format source files
yarn format
# run unit tests in Node
yarn test:node
# run unit tests in Electon
yarn test:browser
# run e2e test in Node (local DAppChain node must be running first)
yarn e2e:node
# run e2e test in Electron (local DAppChain node must be running first)
yarn e2e:browser

The e2e test environment can be configured by changing .env.test (see .env.test.example for default values).

Debugging

To debug loom-js while using it another project:

  1. Clone the Git repo from https://github.com/loomnetwork/loom-js
  2. Inside the loom-js repo run:
    yarn link
    yarn build:dev
    
  3. In your project repo run yarn link loom-js.
  4. Debug your project normally.

yarn build:dev will compile the TypeScript source to target ES2017, which requires a lot less transformation of async/await constructs than the ES5 code released on NPM.

Regenerating Protobufs

Whenever you change src/proto/loom.proto, or src/tests/tests.proto you will need to regenerate the corresponding *_pb.js by running:

yarn proto

The shell must be able to locate the protoc binary, which can be obtained from https://github.com/google/protobuf/releases

Custom Middlewares

Install the loom-js beta version: yarn add loom-js@beta

LoomProvider takes a custom function that lets you customize what middlewares it runs. For example, we have an experimental nonce caching middleware that has more advanced nonce tracking. You can add it as such:

const setupMiddlewareFn = function(client, privateKey) {
  const publicKey = CryptoUtils.publicKeyFromPrivateKey(privateKey)
  return [new CachedNonceTxMiddleware(publicKey, client), new SignedTxMiddleware(privateKey)]
}

const loomProviderObj = new LoomProvider(client, privateKey, setupMiddlewareFn)

More examples here: https://github.com/loomnetwork/loom-js/blob/master/src/tests/e2e/loom-provider-web3-middlewares-tests.ts

JSON RPC supported calls

LoomProvider combined with Web3 supports the following JSON RPC calls

Current implemented

  • [x] eth_accounts
  • [x] eth_blockNumber
  • [x] eth_call
  • [x] eth_estimateGas
  • [x] eth_gasPrice
  • [x] eth_getBlockByHash
  • [x] eth_getBlockByNumber
  • [x] eth_getCode
  • [x] eth_getFilterChanges
  • [x] eth_getLogs
  • [x] eth_getTransactionByHash
  • [x] eth_getTransactionReceipt
  • [x] eth_newBlockFilter
  • [x] eth_newFilter
  • [x] eth_newPendingTransactionFilter
  • [x] eth_sendTransaction
  • [x] eth_subscribe
  • [x] eth_uninstallFilter
  • [x] eth_unsubscribe
  • [x] net_version

Should

  • [ ] eth_getFilterLogs (Returns an array of all logs matching filter with given id)

Maybe

  • [ ] net_peerCount (Returns the current ethereum protocol version)
  • [ ] eth_syncing (Returns an object with data about the sync status or false)
  • [ ] eth_coinbase (Returns the client coinbase address)
  • [ ] web3_clientVersion (Returns the current client version)
  • [ ] eth_getTransactionCount (Returns the number of transactions sent from an address)
  • [ ] eth_getBlockTransactionCountByHash (Returns the number of transactions in a block from a block matching the given block hash)
  • [ ] eth_getBlockTransactionCountByNumber (Returns the number of transactions in a block matching the given block number)

Custom Loom provider methods

Install the loom-js beta version: yarn add loom-js@beta

Sometimes the project requires few functions that aren't provided directly from LoomProvider in this case is possible to add a custom Eth RPC method. You can add it as such:

const loomProviderObj = new LoomProvider(client, privateKey)
loomProviderObj.addCustomMethod('eth_balance', payload => {
  return '0x1'
})

The first param should be the Ethereum RPC call method to add on LoomProvider and the second parameter a callback function with the result

Overwrite Loom provider methods

Install the loom-js beta version: yarn add loom-js@beta

If the project requires to overwrite a RPC function that already exists on LoomProvider. You can add it as such:

loomProvider.overwriteMethod('eth_estimateGas', payload => {
  return '0x123'
})

The first param should be the Ethereum RPC call method to overwrite on LoomProvider and the second parameter a callback function with the result

License

BSD 3-Clause, see LICENSE file for details.

Current Tags

  • 1.60.4                                ...           beta (24 days ago)
  • 1.71.0                                ...           dev (20 days ago)
  • 1.55.0                                ...           latest (6 months ago)

117 Versions

  • 1.71.0                                ...           20 days ago
  • 1.60.4                                ...           24 days ago
  • 1.60.3                                ...           24 days ago
  • 1.60.2                                ...           a month ago
  • 1.70.1                                ...           2 months ago
  • 1.70.0                                ...           2 months ago
  • 1.60.1                                ...           2 months ago
  • 1.60.0                                ...           3 months ago
  • 1.59.1                                ...           3 months ago
  • 1.59.0                                ...           4 months ago
  • 1.58.0                                ...           4 months ago
  • 1.57.3                                ...           5 months ago
  • 1.57.2                                ...           5 months ago
  • 1.57.1                                ...           5 months ago
  • 1.57.0                                ...           5 months ago
  • 1.56.0                                ...           5 months ago
  • 1.55.0                                ...           6 months ago
  • 1.54.2                                ...           6 months ago
  • 1.54.1                                ...           6 months ago
  • 1.54.0                                ...           6 months ago
  • 1.53.0                                ...           7 months ago
  • 1.52.0                                ...           7 months ago
  • 1.51.1                                ...           7 months ago
  • 1.51.0                                ...           7 months ago
  • 1.50.0                                ...           7 months ago
  • 1.49.4                                ...           8 months ago
  • 1.49.3                                ...           9 months ago
  • 1.49.2                                ...           9 months ago
  • 1.49.1                                ...           9 months ago
  • 1.49.0                                ...           9 months ago
  • 1.48.0                                ...           9 months ago
  • 1.47.0                                ...           9 months ago
  • 1.46.3                                ...           9 months ago
  • 1.46.2                                ...           9 months ago
  • 1.46.1                                ...           9 months ago
  • 1.46.0                                ...           9 months ago
  • 1.45.0                                ...           10 months ago
  • 1.44.1                                ...           10 months ago
  • 1.44.0                                ...           10 months ago
  • 1.43.0                                ...           10 months ago
  • 1.42.2                                ...           10 months ago
  • 1.42.1                                ...           10 months ago
  • 1.42.0                                ...           10 months ago
  • 1.41.3                                ...           10 months ago
  • 1.41.2                                ...           10 months ago
  • 1.41.1                                ...           10 months ago
  • 1.41.0                                ...           10 months ago
  • 1.40.1                                ...           10 months ago
  • 1.40.0                                ...           10 months ago
  • 1.39.0                                ...           a year ago
  • 1.38.4                                ...           a year ago
  • 1.38.3                                ...           a year ago
  • 1.38.2                                ...           a year ago
  • 1.38.1                                ...           a year ago
  • 1.38.0                                ...           a year ago
  • 1.37.3                                ...           a year ago
  • 1.37.2                                ...           a year ago
  • 1.37.1                                ...           a year ago
  • 1.37.0                                ...           a year ago
  • 1.30.3                                ...           a year ago
  • 1.36.2                                ...           a year ago
  • 1.36.1                                ...           a year ago
  • 1.36.0                                ...           a year ago
  • 1.35.0                                ...           a year ago
  • 1.34.0                                ...           a year ago
  • 1.33.1                                ...           a year ago
  • 1.33.0                                ...           a year ago
  • 1.32.0                                ...           a year ago
  • 1.31.0                                ...           a year ago
  • 1.30.2                                ...           a year ago
  • 1.30.1                                ...           a year ago
  • 1.30.0                                ...           a year ago
  • 1.29.1                                ...           a year ago
  • 1.29.0                                ...           a year ago
  • 1.28.1                                ...           a year ago
  • 1.28.0                                ...           a year ago
  • 1.27.1                                ...           a year ago
  • 1.27.0                                ...           a year ago
  • 1.26.0                                ...           a year ago
  • 1.25.0                                ...           a year ago
  • 1.24.0                                ...           a year ago
  • 1.23.0                                ...           a year ago
  • 1.22.0                                ...           a year ago
  • 1.21.0                                ...           a year ago
  • 1.20.1                                ...           a year ago
  • 1.20.0                                ...           a year ago
  • 1.19.0                                ...           a year ago
  • 1.18.0                                ...           a year ago
  • 1.17.0                                ...           a year ago
  • 1.16.2                                ...           a year ago
  • 1.16.1                                ...           a year ago
  • 1.16.0                                ...           a year ago
  • 1.15.0                                ...           a year ago
  • 1.14.0                                ...           a year ago
  • 1.13.0                                ...           a year ago
  • 1.12.2                                ...           a year ago
  • 1.12.0                                ...           a year ago
  • 1.11.1                                ...           a year ago
  • 1.11.0                                ...           a year ago
  • 1.10.0                                ...           a year ago
  • 1.9.0                                ...           a year ago
  • 1.8.0                                ...           2 years ago
  • 1.7.1                                ...           2 years ago
  • 1.7.0                                ...           2 years ago
  • 1.6.0                                ...           2 years ago
  • 1.5.0                                ...           2 years ago
  • 1.4.5                                ...           2 years ago
  • 1.4.4                                ...           2 years ago
  • 1.4.3                                ...           2 years ago
  • 1.3.3                                ...           2 years ago
  • 1.3.2                                ...           2 years ago
  • 1.3.1                                ...           2 years ago
  • 1.3.0                                ...           2 years ago
  • 1.2.0                                ...           2 years ago
  • 1.1.1                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 1
This Month 118
Last Day 0
Last Week 117
Last Month 52
Dependencies (12)
Dev Dependencies (27)

Copyright 2014 - 2017 © taobao.org |