Using the Data Anchor
Last updated
Last updated
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.
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:
The payer
is an Arc<Keypair>
that points to the Solana keypair to use with the client
The program_id
is the address of the on-chain blober program to interact with
The indexer_url
is an optional parameter if using our indexer service
The config
is a solana_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:
To upload data, store it in a file and point the CLI to that file:
The data
is a slice of bytes (&[u8]
)
The fee
is a fee strategy that determines the priority fee
The 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:
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.
In addition, you can also request a proof of inclusion or proof of completeness from the indexer:
This contains metadata that prove that the indexer's return value is correct, and it hasn’t tampered with the original data posted on-chain.