Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c739a3d

Browse files
bitmonerod basic example 2 added.
1 parent bf6241d commit c739a3d

File tree

4 files changed

+99
-10
lines changed

4 files changed

+99
-10
lines changed

README.md

Lines changed: 68 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def main():
6464
data=json.dumps(rpc_input),
6565
headers=headers)
6666

67-
# preaty print json outout
67+
# pretty print json output
6868
print(json.dumps(response.json(), indent=4))
6969

7070
if __name__ == "__main__":
@@ -99,18 +99,19 @@ The baisc bitmonerod rpc calls are as follows:
9999
- get_info
100100
- get_connections
101101

102+
103+
**Prerequsits**
104+
105+
Before executing this code make sure that bitmonerod is running.
106+
102107
**Basic example showing how to get a block header**
103108
```python
104109
import requests
105110
import json
106111

107-
**Prerequsits**
108-
109-
Before executing this code make sure that bitmonerod is running.
110-
111112
def main():
112113

113-
# simple wallet is running on the localhost and port of 18082
114+
# bitmonerod is running on the localhost and port of 18081
114115
url = "http://localhost:18081/json_rpc"
115116

116117
# standard json header
@@ -134,12 +135,72 @@ def main():
134135
data=json.dumps(rpc_input),
135136
headers=headers)
136137

137-
# preaty print json outout
138+
# pretty print json output
139+
print(json.dumps(response.json(), indent=4))
140+
141+
if __name__ == "__main__":
142+
main()
143+
```
144+
145+
Generated output:
146+
```python
147+
{
148+
"result": {
149+
"status": "OK",
150+
"block_header": {
151+
"difficulty": 756932534,
152+
"height": 796743,
153+
"nonce": 8389,
154+
"depth": 46,
155+
"orphan_status": false,
156+
"hash": "d78e2d024532d8d8f9c777e2572623fd0f229d72d9c9c9da3e7cb841a3cb73c6",
157+
"timestamp": 1445741816,
158+
"major_version": 1,
159+
"minor_version": 0,
160+
"prev_hash": "dff9c6299c84f945fabde9e96afa5d44f3c8fa88835fb87a965259c46694a2cd",
161+
"reward": 8349972377827
162+
}
163+
},
164+
"jsonrpc": "2.0",
165+
"id": "0"
166+
}
167+
```
168+
169+
**Basic example showing how to get a mining status**
170+
```python
171+
import requests
172+
import json
173+
174+
def main():
175+
176+
# bitmonerod' is running on the localhost and port of 18081
177+
url = "http://localhost:18081/mining_status"
178+
179+
# standard json header
180+
headers = {'content-type': 'application/json'}
181+
182+
# execute the rpc request
183+
response = requests.post(
184+
url,
185+
headers=headers)
186+
187+
# pretty print json output
138188
print(json.dumps(response.json(), indent=4))
139189

140190
if __name__ == "__main__":
141191
main()
142192
```
193+
Generated output:
194+
195+
```python
196+
{
197+
"status": "OK",
198+
"threads_count": 2,
199+
"speed": 117,
200+
"active": true,
201+
"address": "48daf1rG3hE1Txapcsxh6WXNe9MLNKtu7W7tKTivtSoVLHErYzvdcpea2nSTgGkz66RFP4GKVAsTV14v6G3oddBTHfxP6tU"
202+
}
203+
```
143204

144205
More examples are comming soon.
145206

src/bitmonerod_basic_rpc_call_01.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
def main():
1414

15-
# simple wallet is running on the localhost and port of 18082
15+
# bitmonerod is running on the localhost and port of 18081
1616
url = "http://localhost:18081/json_rpc"
1717

1818
# standard json header
@@ -36,7 +36,7 @@ def main():
3636
data=json.dumps(rpc_input),
3737
headers=headers)
3838

39-
# preaty print json outout
39+
# pretty print json output
4040
print(json.dumps(response.json(), indent=4))
4141

4242
if __name__ == "__main__":
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Basic example of json-rpc calls to Monero's bitmonerod.
2+
#
3+
# The example gets a header a mining status
4+
#
5+
# The bitmonerod RPC docs are here: not avaliable
6+
7+
8+
import requests
9+
import json
10+
11+
def main():
12+
13+
# bitmonerod' is running on the localhost and port of 18081
14+
url = "http://localhost:18081/mining_status"
15+
16+
# standard json header
17+
headers = {'content-type': 'application/json'}
18+
19+
# execute the rpc request
20+
response = requests.post(
21+
url,
22+
headers=headers)
23+
24+
# pretty print json output
25+
print(json.dumps(response.json(), indent=4))
26+
27+
if __name__ == "__main__":
28+
main()

src/simplewallet_basic_rpc_call.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def main():
3131
data=json.dumps(rpc_input),
3232
headers=headers)
3333

34-
# preaty print json outout
34+
# pretty print json output
3535
print(json.dumps(response.json(), indent=4))
3636

3737
if __name__ == "__main__":

0 commit comments

Comments
 (0)