Skip to content

Commit

Permalink
add more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
camfairchild committed Aug 29, 2024
1 parent f9eb04f commit 1d09e0b
Showing 1 changed file with 152 additions and 1 deletion.
153 changes: 152 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,94 @@ delegated_info: List[Tuple[DelegateInfo, int]] = DelegateInfo.decode_delegated(
))
```

### NeuronInfo
#### get_neuron
```python
import bittensor
from bt_decode import NeuronInfo

# Setup subtensor connection
subtensor = bittensor.subtensor()
NETUID = 1
UID = 0
# Grab result from RuntimeAPI
hex_bytes_result = sub.query_runtime_api(
runtime_api="NeuronInfoRuntimeApi",
method="get_neuron",
params=[NETUID, UID]
)
# Decode scale-encoded NeuronInfo
neuron: NeuronInfo = NeuronInfo.decode(
bytes.fromhex(
hex_bytes_result
))
```

#### get_neurons
```python
import bittensor
from bt_decode import NeuronInfo

# Setup subtensor connection
subtensor = bittensor.subtensor()
NETUID = 1
# Grab result from RuntimeAPI
hex_bytes_result = sub.query_runtime_api(
runtime_api="NeuronInfoRuntimeApi",
method="get_neurons",
params=[NETUID]
)
# Decode scale-encoded NeuronInfo
neurons: List[NeuronInfo] = NeuronInfo.decode(
bytes.fromhex(
hex_bytes_result
))
```

### NeuronInfoLite
#### get_neuron
```python
import bittensor
from bt_decode import NeuronInfoLite

# Setup subtensor connection
subtensor = bittensor.subtensor()
NETUID = 1
UID = 0
# Grab result from RuntimeAPI
hex_bytes_result = sub.query_runtime_api(
runtime_api="NeuronInfoRuntimeApi",
method="get_neuron_lite",
params=[NETUID, UID]
)
# Decode scale-encoded NeuronInfoLite
neuron_lite: NeuronInfoLite = NeuronInfoLite.decode(
bytes.fromhex(
hex_bytes_result
))
```

#### get_neurons_lite
```python
import bittensor
from bt_decode import NeuronInfoLite

# Setup subtensor connection
subtensor = bittensor.subtensor()
NETUID = 1
# Grab result from RuntimeAPI
hex_bytes_result = sub.query_runtime_api(
runtime_api="NeuronInfoRuntimeApi",
method="get_neurons_lite",
params=[NETUID]
)
# Decode scale-encoded NeuronInfoLite
neurons_lite: List[NeuronInfoLite] = NeuronInfoLite.decode(
bytes.fromhex(
hex_bytes_result
))
```

### StakeInfo
#### get_stake_info_for_coldkey
```python
Expand Down Expand Up @@ -95,4 +183,67 @@ stake_info: List[Tuple[bytes, List["StakeInfo"]]] = StakeInfo.decode_vec_tuple_v
bytes.fromhex(
hex_bytes_result
))
```
```
### SubnetInfo
#### get_subnet_info
```python
import bittensor
from bt_decode import SubnetInfo

# Setup subtensor connection
subtensor = bittensor.subtensor()
NETUID = 1
# Grab result from RuntimeAPI
hex_bytes_result = sub.query_runtime_api(
runtime_api="SubnetInfoRuntimeApi",
method="get_subnet_info",
params=[NETUID]
)
# Decode scale-encoded SubnetInfo
subnet_info: SubnetInfo = SubnetInfo.decode(
bytes.fromhex(
hex_bytes_result
))
```

#### get_subnets_info
```python
import bittensor
from bt_decode import SubnetInfo

# Setup subtensor connection
subtensor = bittensor.subtensor()
# Grab result from RuntimeAPI
hex_bytes_result = sub.query_runtime_api(
runtime_api="SubnetInfoRuntimeApi",
method="get_subnets_info",
params=[ ]
)
# Decode scale-encoded Optional[SubnetInfo]
subnets_info: List[Optional[SubnetInfo]] = SubnetInfo.decode_vec(
bytes.fromhex(
hex_bytes_result
))
```

### SubnetHyperparameters
#### get_subnet_info
```python
import bittensor
from bt_decode import SubnetHyperparameters

# Setup subtensor connection
subtensor = bittensor.subtensor()
NETUID = 1
# Grab result from RuntimeAPI
hex_bytes_result = sub.query_runtime_api(
runtime_api="SubnetInfoRuntimeApi",
method="get_subnet_hyperparams",
params=[NETUID]
)
# Decode scale-encoded SubnetHyperparameters
subnet_hyper_params: SubnetHyperparameters = SubnetHyperparameters.decode(
bytes.fromhex(
hex_bytes_result
))
```

0 comments on commit 1d09e0b

Please sign in to comment.