opendb_test_rpc
v0.1.4
Published
general purpose library for OpenDB blockchain
Downloads
13
Maintainers
Readme
opendb_test_rpc
OpenDB's client side library
Install
This package requires Node.js v14.20.0 or higher
yarn add opendb_test_rpc
or
npm i opendb_test_rpc
Usage
- Use
async
andawait
to handle requests
import OPENDB from 'opendb_test_rpc'
;(async () => {
// For existing valid websocket endpoint
// please refer to https://document.tn.opendb.co
const endpoint = '$OPENDB_BP_WS_ENDPOINT'
const openDB = new OPENDB(endpoint)
/* fetchBlockByHash */
try {
await openDB.connect();
const response = await openDB.bp.getBlockByHash('5c7dd5cb60fea526fd2178670bbe016867950fc7b70224c2d4b76adc660a12f0');
return response;
} catch (e) {
console.error(e)
}
/* fetchBlockList */
try {
await openDB.connect();
const response = await openDB.bp.getBlockList(1, 3);
return response;
} catch (e) {
rconsole.error(e)
}
/* fetchTransactionByHash */
try {
await openDB.connect();
const response = await openDB.bp.getTransactionByHash("942f47cb2a331ee5c37f5b23b7b3b4261033ccd39cc12fc66adcaa48664f1d6a");
return response;
} catch (e) {
console.log(e);
}
/* fetchTransactionList */
try {
await openDB.connect();
const response = await openDB.bp.getTransactionList(page, size);
return response;
} catch (e) {
console.log(e);
}
})()
/* =============== Block Data =============== */
/* ====== fetchBlockByHash Result */
{
"height": 55188700,
"hash": "5c7dd5cb60fea526fd2178670bbe016867950fc7b70224c2d4b76adc660a12f0",
"timestamp": 1712661847000182000,
"timestamp_human": "2024-04-09T11:24:07.000182111Z",
"version": 16777216,
"producer": "8d7604acfdb391891a4c795f0939425b6d58bd50a81e579d15f06ecd381ad549",
"merkle_root": "e618e37920219dd949a6bc81bf9910936c9ec191d1d92b828ba1ff90dd5a3755",
"parent": "be5990f750cf2b09ec8eb2894668cd3affdd6838191b63378181b7835dd0d5a8",
"tx_count": 3
}
// ====== fetchBlockList Result
{
"blocks": [
{
"height": 55188700,
"hash": "5c7dd5cb60fea526fd2178670bbe016867950fc7b70224c2d4b76adc660a12f0",
"timestamp": 1712661847000182000,
"timestamp_human": "2024-04-09T11:24:07.000182111Z",
"version": 16777216,
"producer": "8d7604acfdb391891a4c795f0939425b6d58bd50a81e579d15f06ecd381ad549",
"merkle_root": "e618e37920219dd949a6bc81bf9910936c9ec191d1d92b828ba1ff90dd5a3755",
"parent": "be5990f750cf2b09ec8eb2894668cd3affdd6838191b63378181b7835dd0d5a8",
"tx_count": 3
},
{
"height": 55188699,
"hash": "be5990f750cf2b09ec8eb2894668cd3affdd6838191b63378181b7835dd0d5a8",
"timestamp": 1712661844000170000,
"timestamp_human": "2024-04-09T11:24:04.00017005Z",
"version": 16777216,
"producer": "8d7604acfdb391891a4c795f0939425b6d58bd50a81e579d15f06ecd381ad549",
"merkle_root": "7e86227f99300da914901c391f7793095bd2d1df6ffb7624603ba7dd0c2553c8",
"parent": "f70c535bbef0a74d3b102592f33ee33ad99696caaf371df9418c7859786b4aa1",
"tx_count": 3
}
],
"pagination": {
"page": 1,
"size": 2,
"total": 318843,
"pages": 159422
}
}
// =============== Transaction Data ===============
// ======== fetchTransactionByHash Result
{
"block_height": 55188700,
"index": 1,
"hash": "942f47cb2a331ee5c37f5b23b7b3b4261033ccd39cc12fc66adcaa48664f1d6a",
"block_hash": "5c7dd5cb60fea526fd2178670bbe016867950fc7b70224c2d4b76adc660a12f0",
"timestamp": 1712661845770187800,
"timestamp_human": "2024-04-09T11:24:05.770187851Z",
"type": 9,
"address": "ba0ba731c7a76ccef2c1170f42038f7e228dfb474ef0190dfe35d9a37911ed37",
"raw": "{\"Space\":33172803584,\"Memory\":14789107712,\"LoadAvgPerCPU\":0.0275,\"TargetUser\":null,\"GasPrice\":1,\"TokenType\":0,\"NodeID\":\"000005aa62048f85da4ae9698ed59c14ec0d48a88a07c15a32265634e7e64ade\",\"Nonce\":318843,\"TxType\":9,\"Timestamp\":\"2024-04-09T11:24:05.770187851Z\",\"DataHash\":\"942f47cb2a331ee5c37f5b23b7b3b4261033ccd39cc12fc66adcaa48664f1d6a\",\"Signee\":{\"Curve\":{\"P\":115792089237316195423570985008687907853269984665640564039457584007908834671663,\"N\":115792089237316195423570985008687907852837564279074904382605163141518161494337,\"B\":7,\"Gx\":55066263022277343669578718895168534326250603453777594175500187360389116729240,\"Gy\":32670510020758816978083085130507043184471273380659243275938904335757337482424,\"BitSize\":256,\"Name\":\"\",\"H\":1},\"X\":46889149913685178140156963369364502857171763704599626739506996032145349700896,\"Y\":107351296487730405960229873787712063587054507408879896649250634583933168665635},\"Signature\":{\"R\":48816205973163661129696558208109977111499883738533422344063974348392988798502,\"S\":32520652476819776705229003905131857051523200598119728185685160196802626427851}}",
"tx": {
"DataHash": "942f47cb2a331ee5c37f5b23b7b3b4261033ccd39cc12fc66adcaa48664f1d6a",
"GasPrice": 1,
"LoadAvgPerCPU": 0.0275,
"Memory": 14789107712,
"NodeID": "000005aa62048f85da4ae9698ed59c14ec0d48a88a07c15a32265634e7e64ade",
"Nonce": 318843,
"Signature": {
"R": 4.8816205973163663e+76,
"S": 3.2520652476819775e+76
},
"Signee": {
"Curve": {
"B": 7,
"BitSize": 256,
"Gx": 5.5066263022277344e+76,
"Gy": 3.2670510020758816e+76,
"H": 1,
"N": 1.157920892373162e+77,
"Name": "",
"P": 1.157920892373162e+77
},
"X": 4.6889149913685175e+76,
"Y": 1.073512964877304e+77
},
"Space": 33172803584,
"TargetUser": null,
"Timestamp": "2024-04-09T11:24:05.770187851Z",
"TokenType": 0,
"TxType": 9
}
}
// ======== fetchTransactionList Result
{
"transactions": [
{
"block_height": 55188700,
"index": 2,
"hash": "db47d3ae0010ef44e56536f6a0f84fd1dcfc94ce425f09176151400ab505fbb9",
"block_hash": "5c7dd5cb60fea526fd2178670bbe016867950fc7b70224c2d4b76adc660a12f0",
"timestamp": 1712661845716714500,
"timestamp_human": "2024-04-09T11:24:05.716714379Z",
"type": 9,
"address": "1a7b0959bbd0d0ec529278a61c0056c277bffe75b2646e1699b46b10a90210be",
"raw": "{\"Space\":33172803584,\"Memory\":14789107712,\"LoadAvgPerCPU\":0.0275,\"TargetUser\":null,\"GasPrice\":1,\"TokenType\":0,\"NodeID\":\"000005f4f22c06f76c43c4f48d5a7ec1309cc94030cbf9ebae814172884ac8b5\",\"Nonce\":318843,\"TxType\":9,\"Timestamp\":\"2024-04-09T11:24:05.716714379Z\",\"DataHash\":\"db47d3ae0010ef44e56536f6a0f84fd1dcfc94ce425f09176151400ab505fbb9\",\"Signee\":{\"Curve\":{\"P\":115792089237316195423570985008687907853269984665640564039457584007908834671663,\"N\":115792089237316195423570985008687907852837564279074904382605163141518161494337,\"B\":7,\"Gx\":55066263022277343669578718895168534326250603453777594175500187360389116729240,\"Gy\":32670510020758816978083085130507043184471273380659243275938904335757337482424,\"BitSize\":256,\"Name\":\"\",\"H\":1},\"X\":65719270943604338427905752337893210135845472056018326024127522629670524209686,\"Y\":35497802239556337884222127738547385904561999414342714456895417367493562245332},\"Signature\":{\"R\":38675844899950829639690380171382593038923764384816603554883127048781541395881,\"S\":34237655500141589236100238282878058242372634904943393953512937461423001370083}}",
"tx": {
"DataHash": "db47d3ae0010ef44e56536f6a0f84fd1dcfc94ce425f09176151400ab505fbb9",
"GasPrice": 1,
"LoadAvgPerCPU": 0.0275,
"Memory": 14789107712,
"NodeID": "000005f4f22c06f76c43c4f48d5a7ec1309cc94030cbf9ebae814172884ac8b5",
"Nonce": 318843,
"Signature": {
"R": 3.867584489995083e+76,
"S": 3.4237655500141586e+76
},
"Signee": {
"Curve": {
"B": 7,
"BitSize": 256,
"Gx": 5.5066263022277344e+76,
"Gy": 3.2670510020758816e+76,
"H": 1,
"N": 1.157920892373162e+77,
"Name": "",
"P": 1.157920892373162e+77
},
"X": 6.571927094360434e+76,
"Y": 3.549780223955634e+76
},
"Space": 33172803584,
"TargetUser": null,
"Timestamp": "2024-04-09T11:24:05.716714379Z",
"TokenType": 0,
"TxType": 9
}
},
{
"block_height": 55188700,
"index": 1,
"hash": "942f47cb2a331ee5c37f5b23b7b3b4261033ccd39cc12fc66adcaa48664f1d6a",
"block_hash": "5c7dd5cb60fea526fd2178670bbe016867950fc7b70224c2d4b76adc660a12f0",
"timestamp": 1712661845770187800,
"timestamp_human": "2024-04-09T11:24:05.770187851Z",
"type": 9,
"address": "ba0ba731c7a76ccef2c1170f42038f7e228dfb474ef0190dfe35d9a37911ed37",
"raw": "{\"Space\":33172803584,\"Memory\":14789107712,\"LoadAvgPerCPU\":0.0275,\"TargetUser\":null,\"GasPrice\":1,\"TokenType\":0,\"NodeID\":\"000005aa62048f85da4ae9698ed59c14ec0d48a88a07c15a32265634e7e64ade\",\"Nonce\":318843,\"TxType\":9,\"Timestamp\":\"2024-04-09T11:24:05.770187851Z\",\"DataHash\":\"942f47cb2a331ee5c37f5b23b7b3b4261033ccd39cc12fc66adcaa48664f1d6a\",\"Signee\":{\"Curve\":{\"P\":115792089237316195423570985008687907853269984665640564039457584007908834671663,\"N\":115792089237316195423570985008687907852837564279074904382605163141518161494337,\"B\":7,\"Gx\":55066263022277343669578718895168534326250603453777594175500187360389116729240,\"Gy\":32670510020758816978083085130507043184471273380659243275938904335757337482424,\"BitSize\":256,\"Name\":\"\",\"H\":1},\"X\":46889149913685178140156963369364502857171763704599626739506996032145349700896,\"Y\":107351296487730405960229873787712063587054507408879896649250634583933168665635},\"Signature\":{\"R\":48816205973163661129696558208109977111499883738533422344063974348392988798502,\"S\":32520652476819776705229003905131857051523200598119728185685160196802626427851}}",
"tx": {
"DataHash": "942f47cb2a331ee5c37f5b23b7b3b4261033ccd39cc12fc66adcaa48664f1d6a",
"GasPrice": 1,
"LoadAvgPerCPU": 0.0275,
"Memory": 14789107712,
"NodeID": "000005aa62048f85da4ae9698ed59c14ec0d48a88a07c15a32265634e7e64ade",
"Nonce": 318843,
"Signature": {
"R": 4.8816205973163663e+76,
"S": 3.2520652476819775e+76
},
"Signee": {
"Curve": {
"B": 7,
"BitSize": 256,
"Gx": 5.5066263022277344e+76,
"Gy": 3.2670510020758816e+76,
"H": 1,
"N": 1.157920892373162e+77,
"Name": "",
"P": 1.157920892373162e+77
},
"X": 4.6889149913685175e+76,
"Y": 1.073512964877304e+77
},
"Space": 33172803584,
"TargetUser": null,
"Timestamp": "2024-04-09T11:24:05.770187851Z",
"TokenType": 0,
"TxType": 9
}
}
],
"pagination": {
"page": 1,
"size": 2,
"total": 956535,
"pages": 478268
}
}
APIs
getBlockList
getBlockByHeight
getBlockByHash
getTransactionList
getTransactionListOfBlock
getTransactionByHash