Using the Data Anchor
You can use the Data Anchor's Rust client or CLI tool to post data on-chain and retrieve it from the ledger or our indexer service.
Create Namespace
A namespace represents a data collection, and only your keypair is allowed to write data to it. To create a sample namespace called nitro
on Solana devnet:
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 anArc<Keypair>
that points to the Solana keypair to use with the clientThe
program_id
is the address of the on-chain blober program to interact withThe
indexer_url
is an optional parameter if using our indexer serviceThe
config
is asolana_cli_config::Config
object that sets the transaction RPC details
If you no longer need the data commitment, close the namespace and reclaim the rent from the on-chain account:
data-anchor \
--program-id "2RWsr92iL39YCLiZu7dZ5hron4oexEMbgWDg35v5U5tH" \
--namespace "nitro" \
blober close
Upload Data
To upload data, store it in a file and point the CLI to that file:
let transaction_outcomes = blober_client
.upload_blob(data, fee, blober_id, timeout)
.await?;
The
data
is a slice of bytes (&[u8]
)The
fee
is a fee strategy that determines the priority feeThe
blober_id
is the blober PDA, or namespace, the data should be uploaded to[Optional] The
timeout
specifies how long the client should wait before stopping a data upload attempt (if unset, the client will retry indefinitely)
After the upload is complete, you'll see output similar to the following:
Slot: 3323, Signatures: [2Vkwid2ZTman9zvGq2Tp7P2S5CUWJ2fsZSQzGzaoFkDMAgS9xNccCvNe7PJuHrXNotsVu3BoJAsRa9jdfbZraXvS, faRmYWXPQUDJcFpqffJVE49f5aMSCLYnqp1xH3DZc3SM2Uayc7jReRfR6LjNkFxeuviSJTXMTtSAmAL9tAppwyK, 5XsiKe95nk9GmkceXQkEWapAuAcEQFFYEqMfh5kyeszSxjXepSyDbgzEXmzoQniWMdWvv6mVm5Qbyh9e1i8hHF7K, 2nk2Fj2xwM7oRfsqbmDBNqYwPCLGxHcGUujBo7napJgavMSWFEQ6C9wYmLCkKcuaetBs89vtMbtYzEKaKLKjasKd, 43zzTdgoZBR3sDphuPQTZQHZdT4Ms976bRiY8jguHPZbNPibY3k4EVnrRGKCbUy97i1RzsdMRXkYyv2KJZp9MQZE], Success: true
Fetch Data from Ledger
Use the signatures from the previous step to retrieve the original data from Solana:
let blob = blober_client
.get_ledger_blobs_from_signatures(blober, signatures)
.await?;
Alternatively, set the slot number and number of lookback slots to fetch historical data.
let blobs = blober_client
.get_ledger_blobs(slot, blober, lookback_slots)
.await?;
This returns hex encoded bytes, so remember to hex decode it to get the data back in its original form.
Indexer Services
If you need the data to be stored for a longer time period than the ledger's lifetime of three days, you may want to use an indexer.
To retrieve data from the indexer, all you need to provide is the slot number at which the blob was finalized (You can find this value from the upload command above).
This will produce an output similar to the one from fetching data from the ledger.
Last updated