Crate data_anchor_client

Source
Expand description

§Data Anchor Client

This crate is a Rust client which handles interactions with the Nitro Blober on-chain program and with the Data Anchor indexer service in an optimized way.

§Usage

All you need to do to get started with the client is add it to your project dependencies:

cargo add data-anchor-client

§Connecting

To start uploading and reading data, pass the configs into the client like the following:

let blober_client = BloberClient::builder()
    .payer(payer)
    .program_id(program_id)
    .indexer_from_url(&indexer_url)
    .await?
    .build_with_config(config)
    .await?;
  • The payer is a Arc<Keypair> - a solana keypair you want to use with the client
  • The program_id is the address of the blober on-chain program you want to interact with
  • The indexer_url is an optional parameter to provide if you are using our indexer service
  • The config is a solana_cli_config::Config object used to determine RPC details with which to send the transactions

§Uploading data

Uploading data once you have a blober client is as simple as:

let transaction_outcomes = blober_client.upload_blob(data, fee, blober_id, timeout).await?;
  • The data is a slice of bytes (&[u8]) to upload
  • The fee is a fee strategy for how much you want to send as the priority fee
  • The blober_id is the blober PDA (namespace) you want to upload to
  • The timeout is an optional parameter which specifies how long to wait before discarding a started data upload

The transaction outcomes is a vector of TransactionOutcome enum structs which contain the success state (successfull, failed or unknown) and in case of success the transaction signature and slot at which the transaction landed.

§Querying data

To later retrieve the data that was uploaded, you can either do it from the ledger directly:

let blob = blober_client
    .get_ledger_blobs_from_signatures(blober, signatures)
    .await?;

Where the signatures are the list of signatures you got by sending the upload request.

let blobs = blober_client.get_ledger_blobs(slot, blober, lookback_slots).await?;

Where the slot is the slot at which the upload was finalized and lookback_slots is an optional parameter to limit how many slots before the slot to fetch in the past.

Or from the indexer service with:

let blobs = blober_client.get_blobs(slot, blober).await?;

And getting the indexer proofs (these prove that the indexer is sending you valid data):

let proof = blober_client.get_slot_proof(slot, blober).await?;

For more details, check out the docs.

Structs§

BatchClient
A client that wraps an RpcClient and uses it to submit batches of transactions.
BloberClient
FailedTransaction
A transaction that resulted in an error.
Fee
The expected fees for a blob upload, broken down by source.
Lamports
The smallest fraction of the native Solana token, SOL. 1 lamport = 0.000000001 SOL.
MicroLamports
10^-6 lamports, only used for prioritization fee calculations.
SuccessfulTransaction
A transaction that was successfully confirmed by the network at the desired commitment level.
UnknownTransaction
A transaction that either was not submitted to the network, or it was submitted but not confirmed.

Enums§

BloberClientError
Errors that can occur when interacting with the Blober client.
DeploymentError
FeeStrategy
The strategy to use for calculating the fees for transactions.
IndexerError
LedgerDataBlobError
Errors that can occur when fetching blob data from the ledger.
OutcomeError
Transaction outcomes were not successfull.
Priority
The percentile of recent prioritization fees to use as the compute unit price for a transaction.
TransactionOutcome
The final outcome of a transaction after the [BatchClient] is done, either successfully or due to reaching the timeout.
TransactionType
Transaction types which can be performed by the data_anchor_blober::blober program.
UploadBlobError
An error that can occur when uploading a blob to a blober account.

Type Aliases§

BloberClientResult
Result returned when interacting with the Blober client.