@arcblock/ocap-js
v0.16.2 ocap blockchain arcblock sdk nodejs
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
- Table of Contents
- Notes
- Install
- Usage
- Documentation
- Starter Templates
- CodeSandbox Projects
- OCAP Service CheatSheet
- Contributors
- License
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?
- See docs/example.btc.js for Bitcoin examples.
- See docs/example.eth.js for Ethereum 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
npm i @arcblock/[email protected]
Metadata
- MIT
- Whatever
- wangshijun
- released 1/28/2019