Skip to main content

Using the Prover SDK

The Succinct Prover Node provides Rust libraries for interacting with the Succinct Prover Network APIs.

Creating a Prover Network Client

  1. First, create a network client:
use spn_network_types::prover_network_client::ProverNetworkClient;
use spn_rpc::configure_endpoint;
use tonic::transport::Channel;

// Create a network client
let rpc_url = "https://rpc-production.succinct.xyz";
let channel = configure_endpoint(rpc_url).await?.connect().await?;
let network_client = ProverNetworkClient::new(channel);
  1. Now you can interact with the API:
// Get the balance of an address
use spn_rpc::fetch_balance;

let address = wallet.address().to_vec();
let balance = fetch_balance(&network_client, &address).await?;

Example: Requesting a Proof

Here's a complete example of requesting a proof using the API:

use alloy_primitives::U256;
use alloy_signer_local::PrivateKeySigner;
use spn_network_types::{
MessageFormat, ProofMode, FulfillmentStrategy,
RequestProofRequest, RequestProofRequestBody, Signable,
};

// Set up the account and client
let private_key = "0x...";
let signer = PrivateKeySigner::new_from_hex(private_key)?;
let network_client = ProverNetworkClient::new(channel);

// Get the current nonce
let nonce = network_client
.get_nonce(GetNonceRequest { address: signer.address().to_vec() })
.await?
.into_inner()
.nonce;

// Create the request body
let body = RequestProofRequestBody {
nonce,
vk_hash: hex::decode("0018b32c74d38cdbbcf62bd30414e413fdd5553ed5d33e9ea432a11d6d7ebcf8")?,
version: "sp1-v4.0.0-rc.3".to_string(),
mode: ProofMode::ExecutionAndProof.into(),
strategy: FulfillmentStrategy::Auction.into(),
stdin_uri: "https://artifacts.production.succinct.xyz/stdins/artifact_01jtv7tm61fjsae9cxea76h46p".to_string(),
deadline: time_now() + 300, // 5 minutes from now
cycle_limit: 1249,
gas_limit: 0, // Use cycle_limit
};

// Sign and send the request
let request = RequestProofRequest {
format: MessageFormat::Binary.into(),
signature: body.sign(&signer).into(),
body: Some(body),
};

let response = network_client.request_proof(request).await?;
let request_id = response.into_inner().body.unwrap().request_id;
println!("Created proof request with ID: {}", hex::encode(request_id));

Monitoring a Proof Request

After submitting a proof request, you can monitor its status:

use spn_network_types::{
GetProofRequestStatusRequest, FulfillmentStatus, ExecutionStatus,
};

let request_id = hex::decode("a56e3565919cb373636718c4f78d44dbe3d0af82444d96485248fda3d87e6c3e")?;
let status = network_client
.get_proof_request_status(GetProofRequestStatusRequest { request_id })
.await?
.into_inner();

println!("Fulfillment status: {:?}", FulfillmentStatus::from_i32(status.fulfillment_status));
println!("Execution status: {:?}", ExecutionStatus::from_i32(status.execution_status));

if status.proof_public_uri.is_some() {
println!("Proof available at: {}", status.proof_public_uri.unwrap());
}