ZooBC-SDK
ZooBC-SDK is a small set of libraries written with TypeScript and compiled to be JavaScript, making it easy to implement / integrate applications so that they connect with the P2P API of the nodes in the blockchain for the Web API of the explorer servers and wallet.
Start using ZooBC-SDK
For instructions on how to use web and mobile for a project, please refer to these documents:
Start developing ZooBC-SDK
Installing
Step 1
# Clone this repository
$ git clone https://github.com/zoobc/zoobc-sdk.git
# Go to 'zoobc-sdk' directory
$ cd zoobc-sdk
# Install 'node_modules' packages
$ npm install
or
$ yarn install
Step 2
# Run proto generator
$ ./protogen.sh
Step 3
# Unit testing
$ npm run test
or
$ yarn test
General Usage
Add 'zoobc' packages to your project by executing:
$ npm install zoobc
or
$ yarn add zoobc
Here's an example of basic usage for connection:
import React, { useState, useEffect } from 'react';
import zoobc from 'zoobc';
const App = () => {
const [blocks, setBlocks] = useState([])
const [error, setError] = useState(null)
const [detail, setDetail] = useState(null)
useEffect(() => {
const hosts = [
{ host: 'http://your-ip-address:your-port', name: 'Testnet' },
];
zoobc.Network.list(hosts)
listBlocks();
}, [])
const listBlocks = () => {
zoobc.Block
.getBlocks({height: 0})
.then(res => setBlocks(res.blocksList))
.catch(err => setError(err))
};
const onClickBlockId = (id) => {
zoobc.Block
.getBlockById(id)
.then(res => {
setDetail(res)
setError(null)
})
.catch(err => {
setError(err)
setDetail(null)
})
}
const onClickBlockHeight = (height) => {
zoobc.Block
.getBlockByHeight(height)
.then(res => {
setDetail(res)
setError(null)
})
.catch(err => {
setError(err)
setDetail(null)
})
}
return (
<>
{!!error && (
<>
<div><strong>Error</strong></div>
<code>{JSON.stringify(error)}</code>
</>
)}{!!detail && (
<>
<div><strong>Detail</strong></div>
<code>{JSON.stringify(detail)}</code>
</>
)}
<table>
<thead>
<tr>
<th>Id</th>
<th>Previous Hash</th>
<th>Height</th>
<th>Timestamp</th>
<th>Version</th>
</tr>
</thead>
<tbody>
{blocks.length > 0 &&
blocks.map((data, key) => {
return (
<tr key={key}>
<td onClick={() => onClickBlockId(data.block.id)}>
{data.block.id}
</td>
<td>{data.block.previousblockhash}</td>
<td onClick={() => onClickBlockHeight(data.block.height)}>
{data.block.height}
</td>
<td>{data.block.timestamp}</td>
<td>{data.block.version}</td>
</tr>
);
})}
</tbody>
</table>
</>
)
}
export default App;
Contributors
Thanks to all who have contributed to ZooBC-SDK!
Gungde |
Eko |
Irfan |
Yandi |
Nata |
Bagas |
Kevin |
Adhiim |
Witarsana |
License
This project is licensed under the Apache License - see the LICENSE file for details