Mithril client library
Mithril client library can be used by Rust developers to use the Mithril network in their applications.
It is responsible for handling the different types of data certified by Mithril, and available through a Mithril aggregator:
- Snapshot: list, get, download tarball and record statistics.
- Mithril stake distribution: list and get.
- Cardano transaction: list & get snapshots, get proofs.
- Cardano stake distribution: list, get and get by epoch.
- Certificate: list, get, and chain validation.
-
For more information about the Mithril network, please see the architecture overview.
-
For more information about the Mithril client node, please see this overview.
-
Check out the
Bootstrap a Cardano node
guide.
Here is an updated list of all Mithril networks, including their configurations and current statuses:
Last update: 07/21/2023
- Mainnet
- Preprod
- Preview
- Sanchonet
release-mainnet
β
Information | - |
---|---|
Mithril network | release-mainnet |
Cardano network | mainnet |
Cardano magic Id | - |
Supported | Yes βοΈ |
Status | Beta π’ |
Aggregator endpoint | https://aggregator.release-mainnet.api.mithril.network/aggregator βοΈ |
Genesis verification key | https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration/release-mainnet/genesis.vkey βοΈ |
Era reader adapter type | cardano-chain |
Era reader address | https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration/release-mainnet/era.addr βοΈ |
Era reader verification key | https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration/release-mainnet/era.vkey βοΈ |
Build from | Latest release βοΈ |
release-preprod
β
Information | - |
---|---|
Mithril network | release-preprod π |
Cardano network | preprod |
Cardano magic Id | 1 |
Supported | Yes βοΈ |
Status | Release π’ |
Aggregator endpoint | https://aggregator.release-preprod.api.mithril.network/aggregator βοΈ |
Genesis verification key | https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration/release-preprod/genesis.vkey βοΈ |
Era reader adapter type | cardano-chain |
Era reader address | https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration/release-preprod/era.addr βοΈ |
Era reader verification key | https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration/release-preprod/era.vkey βοΈ |
Build from | Latest release βοΈ |
pre-release-preview
β
Information | - |
---|---|
Mithril network | pre-release-preview π |
Cardano network | preview |
Cardano magic Id | 2 |
Supported | Yes βοΈ |
Status | Pre-release π |
Aggregator endpoint | https://aggregator.pre-release-preview.api.mithril.network/aggregator βοΈ |
Genesis verification key | https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration/pre-release-preview/genesis.vkey βοΈ |
Era reader adapter type | cardano-chain |
Era reader address | https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration/pre-release-preview/era.addr βοΈ |
Era reader verification key | https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration/pre-release-preview/era.vkey βοΈ |
Build from | Latest pre-release βοΈ |
testing-preview
β
β οΈ For developers only
Information | - |
---|---|
Mithril network | testing-preview π |
Cardano network | preview |
Cardano magic Id | 2 |
Supported | Yes βοΈ |
Status | Unstable π΄ |
Aggregator endpoint | https://aggregator.testing-preview.api.mithril.network/aggregator βοΈ |
Genesis verification key | https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration/testing-preview/genesis.vkey βοΈ |
Era reader adapter type | cardano-chain |
Era reader address | https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration/testing-preview/era.addr βοΈ |
Era reader verification key | https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration/testing-preview/era.vkey βοΈ |
Build from | Main branch βοΈ |
testing-sanchonet
β
β οΈ For developers only
Information | - |
---|---|
Mithril network | testing-sanchonet π |
Cardano network | sanchonet |
Cardano magic Id | 4 |
Supported | Yes βοΈ |
Status | Unstable π΄ |
Aggregator endpoint | https://aggregator.testing-sanchonet.api.mithril.network/aggregator βοΈ |
Genesis verification key | https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration/testing-sanchonet/genesis.vkey βοΈ |
Era reader adapter type | cardano-chain |
Era reader address | https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration/testing-sanchonet/era.addr βοΈ |
Era reader verification key | https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration/testing-sanchonet/era.vkey βοΈ |
Build from | Main branch βοΈ |
In this documentation, we use the following generic identifiers:
- YOUR_CARDANO_NETWORK You need to replace this with the name of the network that runs on your Cardano node (eg,
preprod
) - YOUR_AGGREGATOR_ENDPOINT You need to replace this with the endpoint of an aggregator that runs on the Cardano network you are targeting (eg,
https://aggregator.release-preprod.api.mithril.network/aggregator
) - YOUR_GENESIS_VERIFICATION_KEY You need to replace this with the genesis verification key URL that runs on the Cardano network you are targeting (eg,
https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration/release-preprod/genesis.vkey
) - YOUR_ERA_READER_ADAPTER_TYPE You need to replace this with the era reader adapter type used by the Mithril network you are targeting (eg,
cardano-chain
) - YOUR_ERA_READER_ADDRESS You need to replace this with the era reader address URL used by the Mithril network you are targeting (eg,
https://raw.githubusercontent.com/input-output-hk/mithril/main/address.addr
) - YOUR_ERA_READER_VERIFICATION_KEY You need to replace this with the era reader verification key URL used by the Mithril network you are targeting (eg,
https://raw.githubusercontent.com/input-output-hk/mithril/main/TEST_ONLY_era.vkey
)
Resourcesβ
Node | Source repository | Rust documentation |
---|---|---|
Mithril client | βοΈ | βοΈ |
Pre-requisitesβ
-
Install the latest stable version of the correctly configured Rust toolchain.
-
Install Build Tools
build-essential
andm4
. For example, on Ubuntu/Debian/Mint, runsudo apt install build-essential m4
. -
Install OpenSSL development libraries. For example, on Ubuntu/Debian/Mint, run
apt install libssl-dev
Installationβ
In your project, use cargo
to add mithril-client crate as a dependency:
cargo add mithril-client
Mithril client is an asynchronous library, you will need a runtime to execute your futures. We recommend to use the crate tokio, as the library has been tested with it.
Using Mithril client libraryβ
Below is a basic example of how to use most of the functions exposed by the Mithril client library:
use mithril_client::{ClientBuilder, MessageBuilder};
use std::path::Path;
#[tokio::main]
async fn main() -> mithril_client::MithrilResult<()> {
let client = ClientBuilder::aggregator("YOUR_AGGREGATOR_ENDPOINT", "YOUR_GENESIS_VERIFICATION_KEY").build()?;
let snapshots = client.snapshot().list().await?;
let last_digest = snapshots.first().unwrap().digest.as_ref();
let snapshot = client.snapshot().get(last_digest).await?.unwrap();
let certificate = client
.certificate()
.verify_chain(&snapshot.certificate_hash)
.await?;
// Note: the directory must already exist, and the user running this code must have read/write access to it.
let target_directory = Path::new("YOUR_TARGET_DIRECTORY");
client
.snapshot()
.download_unpack(&snapshot, target_directory)
.await?;
if let Err(e) = client.snapshot().add_statistics(&snapshot).await {
println!("Could not increment snapshot download statistics: {:?}", e);
}
let message = MessageBuilder::new()
.compute_snapshot_message(&certificate, target_directory)
.await?;
assert!(certificate.match_message(&message));
Ok(())
}
Snapshot download and certificate chain validation can take quite some time even with a fast computer and network. We have implemented a feedback mechanism for them, more details on it are available in the feedback sub-module.
An example of implementation with the crate indicatif is available in the Mithril repository. To run it, execute the following command:
cargo run -p client-snapshot
or directly from the example crate directory:
cargo run
Here is a working example of the code using the configuration parameters of the release-preprod
network:
use mithril_client::{ClientBuilder, MessageBuilder};
use std::path::Path;
#[tokio::main]
async fn main() -> mithril_client::MithrilResult<()> {
let client = ClientBuilder::aggregator("https://aggregator.release-preprod.api.mithril.network/aggregator", "5b3132372c37332c3132342c3136312c362c3133372c3133312c3231332c3230372c3131372c3139382c38352c3137362c3139392c3136322c3234312c36382c3132332c3131392c3134352c31332c3233322c3234332c34392c3232392c322c3234392c3230352c3230352c33392c3233352c34345d").build()?;
let snapshots = client.snapshot().list().await?;
let last_digest = snapshots.first().unwrap().digest.as_ref();
let snapshot = client.snapshot().get(last_digest).await?.unwrap();
let certificate = client
.certificate()
.verify_chain(&snapshot.certificate_hash)
.await?;
// Note: the directory must already exist, and the user running this code must have read/write access to it.
let target_directory = Path::new(".");
client
.snapshot()
.download_unpack(&snapshot, target_directory)
.await?;
if let Err(e) = client.snapshot().add_statistics(&snapshot).await {
println!("Could not increment snapshot download statistics: {:?}", e);
}
let message = MessageBuilder::new()
.compute_snapshot_message(&certificate, target_directory)
.await?;
assert!(certificate.match_message(&message));
Ok(())
}
You can read the complete developer documentation.