Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
docs feat: wrap query response to save developers a few keys strokes (#78) Feb 18, 2019
src
test
tools support fake both arguments and response messages (#89) Apr 29, 2019
.babelrc
LICENSE chore: update license May 8, 2019
README.cn.md feat: wrap query response to save developers a few keys strokes (#78) Feb 18, 2019
README.md feat: wrap query response to save developers a few keys strokes (#78) Feb 18, 2019
jest.config.js
package.json v0.20.0 May 16, 2019
webpack.config.js fix webpack library target (#13) Aug 20, 2018
yarn.lock refactor and support analytics sdk (#9) Aug 18, 2018

README.md

@arcblock/ocap-js

build status code coverage styled with prettier license

Javascript SDK for OCAP Service by ArcBlock for both Node.js, browser and react-native.

If you are using this SDK in browser environment, babel-polyfill is required.

中文版文档,请移步这里.

Table of Contents

Notes

Since @arcblock/ocap-js v0.11.0, we support user specific rate-limit and page size limit on signed data request, instructions and code snippets to perform signed requests can be found here.

For security reasons, signed requests are only supported in node.js by now, if you want to leverage increased rate-limit and page sizing limit in the browser, consider building an API proxy layer in your DApp.

Install

npm install @arcblock/ocap-js
// or
yarn add @arcblock/ocap-js

Usage

const OCAPClient = require('@arcblock/ocap-js');

// init client
const client = new OCAPClient({
  dataSource: 'eth', // btc, eth
});

// shortcut query
const account = await client.accountByAddress({
  address: '0xe65d3128feafd14d472442608daf94bceb91e333',
});
console.log('ShortcutQuery', account);

// raw query
const result = await client.doRawQuery(`{
  blockByHeight(height:5027689) {
    time
    size
    gasUsed
    gasLimit
    nonce
    reward
    preHash
    size
  }
}`);
console.log('RawQuery', result);

// paged result with shortcut query
const blocks = await client.listBlocks({
  timeFilter: {
    fromHeight: 1000000,
    toHeight: 1000020,
  },
  paging: { size: 5 },
});
console.log('PagedQuery.1', blocks.data.map(x => x.hash));
if (typeof blocks.next === 'function') {
  const blocks2 = await blocks.next();
  console.log('PagedQuery.2', blocks2.data.map(x => x.hash));
}

// shortcut subscription
const subscription = await client.newBlockMined();
subscription.on('data', data => console.log('ShortcutSubscription', data));

// raw subscription
const rawSubscription = await client.doRawSubscription(`
  subscription {
    newBlockMined {
      height
      hash
    }
  }`);
rawSubscription.on('data', data => console.log('RawSubscription', data));

Want more examples?

Documentation

Starter Templates

Start building OCAP DApp with just one command.

CodeSandbox Projects

Start building OCAP DApp without setting up environment.

OCAP Service CheatSheet

Contributors

Name Website
wangshijun https://ocap.arcblock.io

License

MIT © wangshijun

You can’t perform that action at this time.