16 releases
0.4.5 | Jun 26, 2024 |
---|---|
0.4.2 | Feb 17, 2024 |
0.4.0-alpha.4 | Dec 5, 2023 |
0.4.0-alpha.2 | Nov 22, 2023 |
0.2.0 | May 31, 2023 |
#5 in #avalanche
Used in ash_cli
170KB
3.5K
SLoC
ash_sdk
Crate
ash-rs
is a Rust SDK for Avalanche and Ash tools.
It provides a higher level of abstraction than avalanche-types-rs and comes with a CLI that simplifies the interaction with Avalanche networks.
Opinionated structs layout
The library provides an opinionated layout to represent Avalanche networks, Subnets and blockchains. The layout could be represented as follows:
AvalancheNetwork
└── subnets
├── AvalancheSubnet 1
│ ├── blockchains
│ │ ├── AvalancheBlockchain 1
│ │ └── AvalancheBlockchain 2
│ └── validators
│ ├── AvalancheSubnetValidator 1
│ └── AvalancheSubnetValidator 2
└── AvalancheSubnet 2
├── blockchains
│ ├── AvalancheBlockchain 3
│ └── AvalancheBlockchain 4
└── validators
├── AvalancheSubnetValidator 1
└── AvalancheSubnetValidator 2
Avalanche networks
An AvalancheNetwork
is a top level struct that represents an Avalanche network. It contains the list of its AvalancheSubnet
s. Most of the updating methods are implemented on this struct (e.g. update_subnet
, update_blockchains
, etc.).
Avalanche Subnets and validators
An AvalancheSubnet
is a struct that represents an Avalanche Subnet. It contains all the Subnet metadata, the list of its AvalancheBlockchain
s and the list of its validators (as AvalancheSubnetsValidator
s).
Avalanche blockchains
An AvalancheBlockchain
is a struct that represents an Avalanche blockchain. It contains all the blockchain metadata.
Avalanche nodes
An AvalancheNode
is a struct that represents an Avalanche node. An AvalancheNode
is not directly linked to an AvalancheNetwork
as its metadata are retrieved directly from its endpoint.
Configuration
The library relies on YAML configuration files that contains the list of known Avalanche networks. For each network, at least the P-Chain configuration has to be provided (in the Primary Network) with its ID and RPC endpoint. All the other Subnets/blockchains will be retrieved/enriched from the P-Chain.
A default configuration is embedded in the library (see conf/default.yaml) and contains the following networks:
mainnet
andfuji
use the default Avalanche public endpointsmainnet-ankr
andfuji-ankr
use the Ankr Avalanche public endpointsmainnet-blast
andfuji-blast
use the Blast Avalanche public endpoints
Configuration example:
# Default configuration of the mainnet network
avalancheNetworks:
- name: mainnet
subnets:
- id: 11111111111111111111111111111111LpoYY
controlKeys: []
threshold: 0
blockchains:
- id: 11111111111111111111111111111111LpoYY
name: P-Chain
vmType: PlatformVM
rpcUrl: https://api.avax.network/ext/bc/P
- id: 2q9e4r6Mu3U68nU1fYjgbR6JvwrRx36CohpAX5UQxse55x1Q5
name: C-Chain
vmID: mgj786NP7uDwBCcq6YwThhaN8FLyybkCa4zBWTQbNgmK6k9A6
vmType: Coreth
rpcUrl: https://api.avax.network/ext/bc/C/rpc
- id: 2oYMBNV4eNHyqk2fjjV5nVQLDbtmNJzq5s3qs3Lo6ftnC6FByM
name: X-Chain
vmID: jvYyfQTxGMJLuGWa55kdP2p2zSUYsQ5Raupu4TW34ZAUBAbtq
vmType: AvalancheVM
rpcUrl: https://api.avax.network/ext/bc/X
Note: You can generate a configuration file with the CLI using the ash conf init
command.
Usage
One can check out the CLI code to see examples of how to use the library.
Modules
See the docs.rs documentation for more details.
Dependencies
~49–66MB
~1.5M SLoC