JSON RPC - ngchain/ngcore GitHub Wiki
JSON-RPC
Chain
getLatestBlockHeight
request params: null
response result:
- number
example:
$ curl -X POST --data '{"id":0,"method":"getLatestBlockHeight","params":null}' http://127.0.0.1:52521
{"jsonrpc":"2.0","result":9412,"id":0}
getLatestBlockHash
request params: null
response result:
- string(hash)
example:
$ curl -X POST --data '{"id":0,"method":"getLatestBlockHash","params":null}' http://127.0.0.1:52521
{"jsonrpc":"2.0","result":9412,"id":0}
getLatestBlock
request params: null
response result:
- a Block
e.g.
$ curl -X POST --data '{"id":0,"method":"getLatestBlock","params":null}' http://127.0.0.1:
52521
{"jsonrpc":"2.0","result":{"network":1,"height":9411,"timestamp":1594865743,"prevBlockHash":"c1f9dcb0d7a3fcb3006ea64179396683c317f3f3d737e6bafbceb39376147abf","trieHash":"a4e40415f30268c5a070d92fa00e3faa50a884e3e17a2539b90ba0730220186f","difficulty":"50000","nonce":"288d8f536b1befac","txs":[{"network":1,"type":1,"prevBlockHash":"c1f9dcb0d7a3fcb3006ea64179396683c317f3f3d737e6bafbceb39376147abf","convener":0,"participants":["4oLzQmCDMb5sHnuHKFVxrLyfvMJaQ2y3YYHeKX5rs7j3fvH3"],"fee":0,"values":[10000000],"extra":"6e67436f7265","sign":"ef877462e23ad5558d1312aaa7639b08a12e51c6285018b2d1c01bab9bcea9b53cc1618b1841e4ee2318b03d27f04bf7dbcea2da72443a91bd8138f40bdbbe1f","hash":"49438a34728155ff404fe6ebc6711bd1b301f379daed9ecd2f02aa1bc6161256"}],"hash":"deadad922f3f6a77a3baed4ee366a462d414ff63019a0e033b4c1c3e5f478266","powHash":"0000ebf9c909e60d927bc64bf31cebca31643102c81eebae9f248af62277e0a6","txn":1},"id":0}
getBlockByHeight
request params
param | value |
---|---|
height | number |
response result:
- a Block
e.g.
$ curl -X POST --data '{"id":0,"method":"getBlockByHeight","params":{"height": 2}}' http://127.0.0.1:52521
{"jsonrpc":"2.0","result":{"network":1,"height":2,"timestamp":1594126099,"prevBlockHash":"07a8a8d73c14a4f47cdfbe1bc58db69cc087c1c04d682a6006c74914348c51ff","trieHash":"3c2724756e1d04de478d1f2bbc057a6a6cb8c6ee995fc7a9e4a5d454df5d99a5","difficulty":"50000","nonce":"88e8bc4000be41df","txs":[{"network":1,"type":1,"prevBlockHash":"07a8a8d73c14a4f47cdfbe1bc58db69cc087c1c04d682a6006c74914348c51ff","convener":0,"participants":["4oLzQmCDMb5sHnuHKFVxrLyfvMJaQ2y3YYHeKX5rs7j3fvH3"],"fee":0,"values":[10000000],"extra":"6e67436f7265","sign":"3fd94cbd8e9f57a9d1bc53f93bb6baf3a7228acf7c7e8ec9188f61d82ba33c2cf4722f52d481df7006927e153172ced5da44d0eb45bc150e985febb6b3d60451","hash":"f8c7b41aefeefda1745abeb35ed004cf6789b210ff77b60f1880a48ec0292713"}],"hash":"b62839fad8cb9bc718acaaa2e0563af29c03dc2b34b802d9141f10303a1b0307","powHash":"00002be755a162a96b96714343522afe619523bd7959d76d1765b9454ecfb73a","txn":1},"id":0}
getBlockByHash
request params
param | value |
---|---|
hash | string |
response result: a Block
e.g.
$ curl -X POST --data '{"id":0,"method":"getBlockByHash","params":{"hash": "efc79f1312662257ac1922c1aad25c89d14e50e09a16fa0cb35e0918ec4410a9"}}' http://127.0.0.1:52521
{"jsonrpc":"2.0","result":{"network":1,"height":9426,"timestamp":1594868246,"prevBlockHash":"f04134bd36dd453bd8f13c9027825e0141c0f2d24404322936ac465f87b05080","trieHash":"3b1df695cea1bfdcda0176b542a18a06eff58800307e91050c9e8f6906bd14e6","difficulty":"50000","nonce":"728d6746625daecb","txs":[{"network":1,"type":1,"prevBlockHash":"f04134bd36dd453bd8f13c9027825e0141c0f2d24404322936ac465f87b05080","convener":0,"participants":["4oLzQmCDMb5sHnuHKFVxrLyfvMJaQ2y3YYHeKX5rs7j3fvH3"],"fee":0,"values":[10000000],"extra":"6e67436f7265","sign":"16dfd0ea788d87344e8151159d68f591504a7453974c22e6867b01f4ea2ed15a3a4d46b24acb66b3aae662b05e4f4801bef9b559153a34632a239a73831fbcba","hash":"15b3ae17e8ed78371ffc89dfad2490d7c11aba9553b015ae0a38209c14e3a786"}],"hash":"efc79f1312662257ac1922c1aad25c89d14e50e09a16fa0cb35e0918ec4410a9","powHash":"00006eeafa4a3cf0137e63af4074673f4930c47266ab73311ebdf321ab9c859e","txn":1},"id":0}
getTxByHash
request params
param | value |
---|---|
hash | string |
response result:
field | value |
---|---|
onChain | bool |
Tx | a Tx when tx exists, or null |
e.g.
$ curl -X POST --data '{"id":0,"method":"getTxByHash","params":{"hash": "e173d8938a35fbf1ffae839091d09a461f91d5a712d90e92c4c67977514a6e9a"}}' http://127.0.0.1:52521
{"jsonrpc":"2.0","result":{"onChain":true,"tx":{"network":1,"type":1,"prevBlockHash":"efc79f1312662257ac1922c1aad25c89d14e50e09a16fa0cb35e0918ec4410a9","convener":0,"participants":["4oLzQmCDMb5sHnuHKFVxrLyfvMJaQ2y3YYHeKX5rs7j3fvH3"],"fee":0,"values":[10000000],"extra":"6e67436f7265","sign":"18897370434100a995ae7bc99338f96aeeaeb1b503d5ef0860a54bab4cacc5fb722dfe70ae60575b891f5956fb279d80956d78caad10d2e879e6bf380126f968","hash":"e173d8938a35fbf1ffae839091d09a461f91d5a712d90e92c4c67977514a6e9a"}},"id":0}
P2P
addPeer
request params
param | value |
---|---|
peerMultiAddr | string |
response result: null
getNetwork
request params: null
response result: string
e.g.
$ curl -X POST --data '{"id":0,"method":"getNetwork","params":null}' http://127.0.0.1:52521
{"jsonrpc":"2.0","result":"TESTNET","id":0}
getPeers
request params: null
response result: a list of peerID
e.g.
$ curl -X POST --data '{"id":0,"method":"getPeers","params":null}' http://127.0.0.1:52521
{"jsonrpc":"2.0","result":["16Uiu2HAmUYSya7JKUksB7uoo2pw7FcpcZRjC3nqDRtWk6ok2UdJV","16Uiu2HAmRZPWpQDGSqfWFKeH6cPRVKdhN3Q4Gyt1Xo86mr8rhwyu","16Uiu2HAmRCHKtLwjzRCju4fF1BDirzAKe6VAeZx8SsoZZKy49ox6"],"id":0}
Sheet
getAccountsByAddress
request params
param | value |
---|---|
address | string |
response result: a list of accounts
$ curl -X POST --data '{"id":0,"method":"getAccountsByAddress","params": {"address": "4oLzQmCDMb5sHnuHKFVxrLyfvMJaQ2y3YYHeKX5rs7j3fvH3"}}' http://127.0.0.1:52521
{"jsonrpc":"2.0","result":[65535],"id":0}
getBalanceByAddress
request params
param | value |
---|---|
address | string |
response result: the balance in number(unit nanoNG/μNG)
$ curl -X POST --data '{"id":0,"method":"getBalanceByAddress","params": {"address": "4oLzQmCDMb5sHnuHKFVxrLyfvMJaQ2y3YYHeKX5rs7j3fvH3"}}' http://127.0.0.1:52521
{"jsonrpc":"2.0","result":"69098000000","id":0}
getBalanceByNum
request params
param | value |
---|---|
num | number |
response result: the balance in number(unit nanoNG/μNG)
$ curl -X POST --data '{"id":0,"method":"getBalanceByNum","params": {"num": 65535}}' http://127.0.0.1:52521
{"jsonrpc":"2.0","result":"69108000000","id":0}
getAccountByNum
request params
param | value |
---|---|
num | number |
response result: the Account in number
e.g.
$ curl -X POST --data '{"id":0,"method":"getAccountByNum","params": {"num": 65535}}' http://127.0.0.1:52521
{"jsonrpc":"2.0","result":{"num":65535,"owner":"4oLzQmCDMb5sHnuHKFVxrLyfvMJaQ2y3YYHeKX5rs7j3fvH3","contract":"","state":""},"id":0}
sendTx
request params
param | value |
---|---|
rawTx | string, signed raw Tx in hex |
response result: string, tx's hash
signTx
request params
param | value |
---|---|
rawTx | string, unsigned raw Tx in hex |
privateKeys | list of string, each string represents the privateKey in hex |
response result: string, signed raw Tx in hex
genTransaction
request params
param | value |
---|---|
convener | number, the account num of the convener |
participants | list of string or number, string represents the address and the number represents account num |
vaules | list of number, one-to-one correspondent with participants |
fee | number, coins to burnt |
extra | string, raw bytes in hex |
response result: string, unsigned raw Tx in hex
genRegister
request params
param | value |
---|---|
owner | string, a address, will own the new account |
num | number, the account num registered for |
response result: string, unsigned raw Tx in hex
genLogout
request params
param | value |
---|---|
convener | number, the account num to logout |
fee | number, coins to burnt |
extra | string, raw bytes in hex |
response result: string, unsigned raw Tx in hex
genAssign & genAppend
request params
param | value |
---|---|
convener | number, the account num of the convener |
fee | number, coins to burnt |
extra | string, raw bytes in hex |
response result: string, unsigned raw Tx in hex
Mining
getBlockTemplate
request params: null
response result: a Block
submitBlock
request params: a Block
response result: string, hash of the Block
getWork
request params: null
response result:
field | value |
---|---|
seed | string, seed for RandomX cache |
raw | string, raw of PoW header in hex |
block | string, raw of whole block template in hex |
submitWork
request params
param | value |
---|---|
nonce | string, raw nonce in hex |
block | string, raw block template in hex from getWork |
response result: null