Skip to content

Commit 997aa4d

Browse files
Merge pull request #27 from nguyenphuminh/json-rpc-v0.13.0
Update RPC server + add docs
2 parents 534f411 + 0d6ea94 commit 997aa4d

File tree

3 files changed

+494
-27
lines changed

3 files changed

+494
-27
lines changed

JSON-RPC.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# JSON-RPC APIs
2+
3+
## What are JSON-RPC APIs?
4+
5+
JSON-RPC APIs are APIs provided by running a JeChain RPC server. They can be used by apps or additional tools to interact with the node, thus also getting access to the network, being able to send transactions from the app and getting the pieces of blockchain data like blocks, account balance and more.
6+
7+
8+
## APIs
9+
10+
### GET
11+
12+
* `/get_blockNumber`:
13+
* Use case: Get the latest block number.
14+
* Reply body: `{ success: true, payload: { blockNumber: <block_number> } }`
15+
16+
* `/get_address`:
17+
* Use case: Get the JeChain address from the RPC server.
18+
* Reply body: `{ success: true, payload: { address: <address> } }`
19+
20+
* `/get_work`:
21+
* Use case: Get hash and nonce from the latest block.
22+
* Reply body: `{ success: true, payload: { hash: <hash>, nonce: <nonce> } }`
23+
24+
### POST
25+
26+
* `/get_blockByHash`:
27+
* Use case: Get block by hash.
28+
* Request body: `{ params: { hash: <hash> } }`
29+
* Reply body: `{ success: true, payload: { block: <block> } }`
30+
* Error body:
31+
* Invalid request (not enough params):
32+
* Status: 400
33+
* Body: `{ success: false, payload: null, error: { message: "Invalid request." } }`
34+
* Invalid block hash (block with given hash not found):
35+
* Status: 400
36+
* Body: `{ success: false, payload: null, error: { message: "Invalid block hash." } }`
37+
38+
* `/get_blockByNumber`:
39+
* Use case: Get block by block number.
40+
* Request body: `{ params: { blockNumber: <block_number> } }`
41+
* Reply body: `{ success: true, payload: { block: <block> } }`
42+
* Error body:
43+
* Invalid request (not enough params):
44+
* Status: 400
45+
* Body: `{ success: false, payload: null, error: { message: "Invalid request." } }`
46+
* Invalid block number (block with given number not found):
47+
* Status: 400
48+
* Body: `{ success: false, payload: null, error: { message: "Invalid block number." } }`
49+
50+
* `/get_blockTransactionCountByHash`:
51+
* Use case: Get transaction count from block through block hash.
52+
* Request body: `{ params: { hash: <hash> } }`
53+
* Reply body: `{ success: true, payload: { count: <count> } }`
54+
* Error body:
55+
* Invalid request (not enough params):
56+
* Status: 400
57+
* Body: `{ success: false, payload: null, error: { message: "Invalid request." } }`
58+
* Invalid block hash (block with given hash not found):
59+
* Status: 400
60+
* Body: `{ success: false, payload: null, error: { message: "Invalid block hash." } }`
61+
62+
* `/get_blockTransactionCountByNumber`:
63+
* Use case: Get transaction count from block through block number.
64+
* Request body: `{ params: { blockNumber: <block_number> } }`
65+
* Reply body: `{ success: true, payload: { count: <count> } }`
66+
* Error body:
67+
* Invalid request (not enough params):
68+
* Status: 400
69+
* Body: `{ success: false, payload: null, error: { message: "Invalid request." } }`
70+
* Invalid block number (block with given number not found):
71+
* Status: 400
72+
* Body: `{ success: false, payload: null, error: { message: "Invalid block number." } }`
73+
74+
* `/get_balance`:
75+
* Use case: Get balance from address.
76+
* Request body: `{ params: { address: <address> } }`
77+
* Reply body: `{ success: true, payload: { balance: <balance> } }`
78+
* Error body:
79+
* Invalid request (not enough params):
80+
* Status: 400
81+
* Body: `{ success: false, payload: null, error: { message: "Invalid request." } }`
82+
83+
* `/get_code`:
84+
* Use case: Get code from address.
85+
* Request body: `{ params: { address: <address> } }`
86+
* Reply body: `{ success: true, payload: { code: <code> } }`
87+
* Error body:
88+
* Invalid request (not enough params):
89+
* Status: 400
90+
* Body: `{ success: false, payload: null, error: { message: "Invalid request." } }`
91+
92+
* `/sendTransaction`:
93+
* Use case: Send transaction.
94+
* Request body: `{ params: { transaction: <transaction_object> } }`
95+
* Reply body: `{ success: true, payload: { message: "tx received." } }`
96+
* Error body:
97+
* Invalid request (not enough params):
98+
* Status: 400
99+
* Body: `{ success: false, payload: null, error: { message: "Invalid request." } }`
100+
101+
* `/get_transactionByBlockHashAndIndex`:
102+
* Use case: Get transaction through block hash and transaction index.
103+
* Request body: `{ params: { hash: <hash>, index: <index> } }`
104+
* Reply body: `{ success: true, payload: { transaction: <transaction_object> } }`
105+
* Error body:
106+
* Invalid request (not enough params):
107+
* Status: 400
108+
* Body: `{ success: false, payload: null, error: { message: "Invalid request." } }`
109+
* Invalid block hash (block with given hash not found):
110+
* Status: 400
111+
* Body: `{ success: false, payload: null, error: { message: "Invalid block hash." } }`
112+
* Invalid transaction index (transaction with index given not found):
113+
* Status: 400
114+
* Body: `{ success: false, payload: null, error: { message: "Invalid transaction index." } }`
115+
116+
* `/get_transactionByBlockNumberAndIndex`:
117+
* Use case: Get transaction through block number and transaction index.
118+
* Request body: `{ params: { blockNumber: <block_number>, index: <index> } }`
119+
* Reply body: `{ success: true, payload: { transaction: <transaction_object> } }`
120+
* Error body:
121+
* Invalid request (not enough params):
122+
* Status: 400
123+
* Body: `{ success: false, payload: null, error: { message: "Invalid request." } }`
124+
* Invalid block number (block with given number not found):
125+
* Status: 400
126+
* Body: `{ success: false, payload: null, error: { message: "Invalid block number." } }`
127+
* Invalid transaction index (transaction with index given not found):
128+
* Status: 400
129+
* Body: `{ success: false, payload: null, error: { message: "Invalid transaction index." } }`
130+
131+
### Other errors
132+
133+
* Invalid option (non-existent API):
134+
* Status: 404
135+
* Body: `{ success: false, payload: null, error: { message: "Invalid option." } }`

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Use `set` on Windows to set variables.
8484

8585
To properly interact with the node, you should use the JSON-RPC apis, especially if you are creating dapps.
8686

87-
(Documentations will be updated soon).
87+
[Check out docs for JSON-RPC APIs here.](./JSON-RPC.md)
8888

8989
### Using the node manually through code:
9090

0 commit comments

Comments
 (0)