npm

Need private packages and team management tools?Check out npm Orgs. »

@arcblock/ocap-js

0.24.0 • Public • Published

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

install

npm i @arcblock/ocap-js

Downloadsweekly downloads

67

version

0.24.0

license

Apache-2.0

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
  • avatar
Report a vulnerability