zbc-sdk
v0.0.30-pre-release
Published
A small set of libraries to implement applications connect with the P2P API of the nodes in the blockchain
Downloads
30
Maintainers
Readme
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:
General Usage
Add 'zbc-sdk' packages to your project by executing:
$ npm install zbc-sdk
or
$ yarn add zbc-sdk
Here's an example of basic usage for connection:
import React, { useState, useEffect } from 'react';
import zoobc from 'zbc-sdk';
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!
License
This project is licensed under the Apache License - see the LICENSE file for details