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 blober_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
Uploading data
Uploading data once you have a blober client is as simple as:
let transaction_outcomes = blober_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.
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
.await?;
Where the signatures are the list of signatures you got by sending the upload request.
let blobs = blober_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 = blober_client.get_blobs.await?;
And getting the indexer proofs (these prove that the indexer is sending you valid data):
let proof = blober_client.get_slot_proof.await?;
For more details, check out the docs.