Skip to content

Commit 1d09e0b

Browse files
committed
add more examples
1 parent f9eb04f commit 1d09e0b

File tree

1 file changed

+152
-1
lines changed

1 file changed

+152
-1
lines changed

README.md

+152-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,94 @@ delegated_info: List[Tuple[DelegateInfo, int]] = DelegateInfo.decode_delegated(
4545
))
4646
```
4747

48+
### NeuronInfo
49+
#### get_neuron
50+
```python
51+
import bittensor
52+
from bt_decode import NeuronInfo
53+
54+
# Setup subtensor connection
55+
subtensor = bittensor.subtensor()
56+
NETUID = 1
57+
UID = 0
58+
# Grab result from RuntimeAPI
59+
hex_bytes_result = sub.query_runtime_api(
60+
runtime_api="NeuronInfoRuntimeApi",
61+
method="get_neuron",
62+
params=[NETUID, UID]
63+
)
64+
# Decode scale-encoded NeuronInfo
65+
neuron: NeuronInfo = NeuronInfo.decode(
66+
bytes.fromhex(
67+
hex_bytes_result
68+
))
69+
```
70+
71+
#### get_neurons
72+
```python
73+
import bittensor
74+
from bt_decode import NeuronInfo
75+
76+
# Setup subtensor connection
77+
subtensor = bittensor.subtensor()
78+
NETUID = 1
79+
# Grab result from RuntimeAPI
80+
hex_bytes_result = sub.query_runtime_api(
81+
runtime_api="NeuronInfoRuntimeApi",
82+
method="get_neurons",
83+
params=[NETUID]
84+
)
85+
# Decode scale-encoded NeuronInfo
86+
neurons: List[NeuronInfo] = NeuronInfo.decode(
87+
bytes.fromhex(
88+
hex_bytes_result
89+
))
90+
```
91+
92+
### NeuronInfoLite
93+
#### get_neuron
94+
```python
95+
import bittensor
96+
from bt_decode import NeuronInfoLite
97+
98+
# Setup subtensor connection
99+
subtensor = bittensor.subtensor()
100+
NETUID = 1
101+
UID = 0
102+
# Grab result from RuntimeAPI
103+
hex_bytes_result = sub.query_runtime_api(
104+
runtime_api="NeuronInfoRuntimeApi",
105+
method="get_neuron_lite",
106+
params=[NETUID, UID]
107+
)
108+
# Decode scale-encoded NeuronInfoLite
109+
neuron_lite: NeuronInfoLite = NeuronInfoLite.decode(
110+
bytes.fromhex(
111+
hex_bytes_result
112+
))
113+
```
114+
115+
#### get_neurons_lite
116+
```python
117+
import bittensor
118+
from bt_decode import NeuronInfoLite
119+
120+
# Setup subtensor connection
121+
subtensor = bittensor.subtensor()
122+
NETUID = 1
123+
# Grab result from RuntimeAPI
124+
hex_bytes_result = sub.query_runtime_api(
125+
runtime_api="NeuronInfoRuntimeApi",
126+
method="get_neurons_lite",
127+
params=[NETUID]
128+
)
129+
# Decode scale-encoded NeuronInfoLite
130+
neurons_lite: List[NeuronInfoLite] = NeuronInfoLite.decode(
131+
bytes.fromhex(
132+
hex_bytes_result
133+
))
134+
```
135+
48136
### StakeInfo
49137
#### get_stake_info_for_coldkey
50138
```python
@@ -95,4 +183,67 @@ stake_info: List[Tuple[bytes, List["StakeInfo"]]] = StakeInfo.decode_vec_tuple_v
95183
bytes.fromhex(
96184
hex_bytes_result
97185
))
98-
```
186+
```
187+
### SubnetInfo
188+
#### get_subnet_info
189+
```python
190+
import bittensor
191+
from bt_decode import SubnetInfo
192+
193+
# Setup subtensor connection
194+
subtensor = bittensor.subtensor()
195+
NETUID = 1
196+
# Grab result from RuntimeAPI
197+
hex_bytes_result = sub.query_runtime_api(
198+
runtime_api="SubnetInfoRuntimeApi",
199+
method="get_subnet_info",
200+
params=[NETUID]
201+
)
202+
# Decode scale-encoded SubnetInfo
203+
subnet_info: SubnetInfo = SubnetInfo.decode(
204+
bytes.fromhex(
205+
hex_bytes_result
206+
))
207+
```
208+
209+
#### get_subnets_info
210+
```python
211+
import bittensor
212+
from bt_decode import SubnetInfo
213+
214+
# Setup subtensor connection
215+
subtensor = bittensor.subtensor()
216+
# Grab result from RuntimeAPI
217+
hex_bytes_result = sub.query_runtime_api(
218+
runtime_api="SubnetInfoRuntimeApi",
219+
method="get_subnets_info",
220+
params=[ ]
221+
)
222+
# Decode scale-encoded Optional[SubnetInfo]
223+
subnets_info: List[Optional[SubnetInfo]] = SubnetInfo.decode_vec(
224+
bytes.fromhex(
225+
hex_bytes_result
226+
))
227+
```
228+
229+
### SubnetHyperparameters
230+
#### get_subnet_info
231+
```python
232+
import bittensor
233+
from bt_decode import SubnetHyperparameters
234+
235+
# Setup subtensor connection
236+
subtensor = bittensor.subtensor()
237+
NETUID = 1
238+
# Grab result from RuntimeAPI
239+
hex_bytes_result = sub.query_runtime_api(
240+
runtime_api="SubnetInfoRuntimeApi",
241+
method="get_subnet_hyperparams",
242+
params=[NETUID]
243+
)
244+
# Decode scale-encoded SubnetHyperparameters
245+
subnet_hyper_params: SubnetHyperparameters = SubnetHyperparameters.decode(
246+
bytes.fromhex(
247+
hex_bytes_result
248+
))
249+
```

0 commit comments

Comments
 (0)