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:
Connecting
To start uploading and reading data, pass the configs into the client like the following:
let data_anchor_client = builder
.payer
.program_id
.indexer_from_url
.await?
.build_with_config
.await?;
- The
payeris aArc<Keypair>- a solana keypair you want to use with the client - The
program_idis the address of the blober on-chain program you want to interact with - The
indexer_urlis an optional parameter to provide if you are using our indexer service - The
configis asolana_cli_config::Configobject used to determine RPC details with which to send the transactions
Builder options
The builder exposes a few additional helpers. A common pattern is to use an indexer together with the Helius fee estimator:
let client = builder
.payer
.program_id
.indexer_from_url
.await?
.with_helius_fee_estimate
.build_with_config
.await?;
The with_helius_fee_estimate flag enables querying the Helius API for a better
priority fee estimate when sending transactions.
Uploading data
Uploading data once you have a blober client is as simple as:
let transaction_outcomes = data_anchor_client.upload_blob.await?;
- The
datais a slice of bytes (&[u8]) to upload - The
feeis a fee strategy for how much you want to send as the priority fee - The
blober_idis the blober PDA (namespace) you want to upload to - The
timeoutis an optional parameter which specifies how long to wait before discarding a started data upload
The transaction outcomes is a vector of
TransactionOutcomeenum 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.
Estimating fees
Before uploading a blob you can estimate the expected cost using estimate_fees:
let priority = default;
let expected_fees = data_anchor_client
.estimate_fees
.await?;
println!;
Querying data
To later retrieve the data that was uploaded, you can either do it from the ledger directly:
let blob = data_anchor_client
.get_ledger_blobs_from_signatures
.await?;
Where the signatures are the list of signatures you got by sending the upload request.
let blobs = data_anchor_client.get_ledger_blobs.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 = data_anchor_client.get_blobs.await?;
And getting the indexer proofs (these prove that the indexer is sending you valid data):
let proof = data_anchor_client.get_slot_proof.await?;
Complete workflow
The following snippet demonstrates creating a blober, uploading data and fetching it back from the ledger:
use ;
use ;
use Config;
use Keypair;
async
For more details, check out the docs.
API reference
The following table contains small examples for the public methods provided by
DataAnchorClient. Every function is asynchronous and returns a
DataAnchorClientResult.
Blober management
let ns = "example";
client.initialize_blober.await?;
client.close_blober.await?;
Upload helpers
let blob_pubkey = new_unique;
client.upload_blob.await?;
client.discard_blob.await?;
client.estimate_fees.await?;
Ledger queries
client.get_ledger_blobs_from_signatures.await?;
client.get_ledger_blobs.await?;
client.get_blob_messages.await?;
Indexer queries
client.get_blobs.await?;
client.get_blobs_by_blober.await?;
client.get_blobs_by_payer.await?;
client.get_blobs_by_network.await?;
client.get_blobs_by_namespace_for_payer.await?;
client.get_proof.await?;
client.get_proof_for_blob.await?;
Builder helpers
let client = builder
.payer
.program_id
.indexer_from_url
.await?
.with_helius_fee_estimate
.build_with_config
.await?;