AlignedLayer
  • Introduction
    • About Aligned
    • Try Aligned
    • Use cases
    • FAQ
    • Why ZK and Aligned?
  • Architecture
    • Supported Verifiers
    • Key Terms
    • Fast mode
      • Batcher
      • Payment Service Contract
      • Service Manager Contract
      • Operator
      • Aggregator
      • Explorer
    • Aggregation mode
  • Guides
    • Submitting proofs
    • Build your first Aligned Application
      • Modify ZkQuiz Questions
    • Validating public input
    • SDK Intro
    • SDK API Reference
    • Generating proofs for Aligned
    • Generating & submitting proofs of Rust code with ZKRust
    • Setup Aligned Infrastructure Locally
    • Contract Addresses
    • Submitting Batch Without Batcher
    • Aligned CLI
  • Operators
    • Running an operator
    • Operator FAQ
    • Troubleshooting
    • Upgrading Guides
      • Upgrading to v0.14.0
      • Upgrading to v0.10.2
      • Upgrading to v0.9.2
  • Useful links
    • Mainnet Explorer
    • Holesky Explorer
    • All the proof aggregation solutions will use RISC-V zkvms
    • Manifesto
  • Socials
    • Telegram Group
    • Twitter/X
    • Discord
    • Blog
    • Website
    • Github
    • YouTube
Powered by GitBook
On this page
  • Installation
  • Hello World
  1. Guides

SDK Intro

PreviousValidating public inputNextSDK API Reference

Last updated 25 days ago

The Aligned SDK aims to help developers interact with Aligned in a simple way. Using the Aligned SDK, you can do things like submitting and verifying proofs through the Aligned Batcher, as well as checking the inclusion of the verified proofs on-chain. This guide provides an overview of the SDK, its installation, usage, and API details.

You can check the list of supported verifiers .

Installation

To use this SDK in your Rust project, add the following to your Cargo.toml:

[dependencies]
aligned-sdk = { git = "https://github.com/yetanotherco/aligned_layer", tag="v0.15.2" }

To find the latest release tag go to and copy the version of the release that has the latest badge.

Hello World

To get the SDK up and running in your project, you must first import it

use aligned_sdk::core::types::{PriceEstimate, AlignedVerificationData, Network, ProvingSystemId, VerificationData};
use aligned_sdk::sdk::{estimate_fee, submit_and_wait, get_nonce_from_ethereum};

And then you can do a simple call of, for example, get_nonce_from_ethereum

const NETWORK: Network = Network::Holesky;

fn main() {
    let rpc_url = args.rpc_url.clone();
    let keystore_password = rpassword::prompt_password("Enter keystore password: ")
        .expect("Failed to read keystore password");
    let wallet = LocalWallet::decrypt_keystore(args.keystore_path, &keystore_password)
        .expect("Failed to decrypt keystore")
        .with_chain_id(17000u64);

    // Call to SDK:
    let nonce = get_nonce_from_ethereum(&rpc_url, wallet.address(), NETWORK).await
    .expect("Failed to get next nonce");
}

Or you can make a more complex call to submit a proof:

fn main() {
    let rpc_url = args.rpc_url.clone();
    let verification_data = VerificationData {
        proving_system: ProvingSystemId::SP1,
        proof,
        proof_generator_addr: wallet.address(),
        vm_program_code: Some(ELF.to_vec()),
        verification_key: None,
        pub_input: None,
    };
    let keystore_password = rpassword::prompt_password("Enter keystore password: ")
        .expect("Failed to read keystore password");
    let wallet = LocalWallet::decrypt_keystore(args.keystore_path, &keystore_password)
        .expect("Failed to decrypt keystore")
        .with_chain_id(17000u64);
    let max_fee = estimate_fee(&rpc_url, PriceEstimate::Instant)
        .await
        .expect("failed to fetch gas price from the blockchain");

    // Call to SDK:
    match submit_and_wait_verification(
        &rpc_url,
        Network::Holesky,
        &verification_data,
        max_fee,
        wallet.clone(),
        nonce
    )
    .await
    {
        Ok(maybe_aligned_verification_data) => match maybe_aligned_verification_data {
            Some(aligned_verification_data) => {
                println!(
                    "Proof submitted and verified successfully on batch {}",
                    hex::encode(aligned_verification_data.batch_merkle_root)
                );

            }
            None => {
                println!("Proof submission failed. No verification data");
            }
        },
        Err(e) => {
            println!("Proof verification failed: {:?}", e);
        }
    }
}

(code extract from )

In the we will dive deeper into what does each argument mean, and what other functions does Aligned SDK contain.

here
releases
next section,
ZKQuiz example