Query Data With Javascript

Getting the query result with OCAP playground or postman is cool, but we want to use it in our own application. We provide several SDKs so that you can retrieve data easily with your favorite language. Here we use OCAP javascript SDK as an example. Let's create a new project and then add @arcblock/ocap-js:

$ mkdir ocap-js-test
$ cd ocap-js-test
$ npm init
$ npm install @arcblock/ocap-js --save
$ touch index.js
1
2
3
4
5

Then open index.js and add these contents:

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

// init client
const client = new OCAPClient({
  dataSource: 'btc', // currently `btc` and `eth` is supported
});

const queries = client.getQueries();

console.log(queries);

client
  .transactionsByAddress({
    receiver: '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa',
  })
  .then(data => console.log(data));
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Last Updated: 11/30/2018, 10:39:27 AM