Usage
Understand the basics for connecting to Recall and using buckets.
The most basic usage will likely involve connecting to the network, creating an bucket, and then adding or getting objects. This page walks through each step and provides examples to help you get started.
Signer & provider setup
To create a bucket, you'll need to use the JsonRpcProvider
from the recall_provider
crate plus
various recall_sdk
types.
Here's a simple example. The signer.init_sequence()
call is optional, but without it, you'll run
into issues with out of sync sequences (nonces). It's best to call init_sequence
unless you're
firing many transactions at once.
Creating a bucket
To create a bucket, you'll need to use the Bucket::new
method, which takes a few arguments:
- The RPC provider.
- The signer.
- An optional
owner
address, which defaults to the signer's address. - A
HashMap
of metadata to assign to the bucket (useDefault::default()
to create an empty map). - Lastly, optional gas parameters (these can be imported from
recall_provider::message::GasParams
).
Note the second value returned is the onchain transaction that created the bucket.
Adding an object
We can extend the example above to add an object to the bucket. The add
method is used to add an
object to the bucket given a provider, signer, the object's desired key (e.g., my/key
), and
options that control its behavior. For example, you can add other metadata to an object or specify
how to handle overwriting an existing object.
Querying objects
To list an object, you can use the query
method. This method comes with available query options to
refine your results:
prefix
: The prefix of the keys you want to list.delimiter
: The delimiter to use when listing keys.start_key
: The key to start listing keys from.limit
: The maximum number of keys to list.height
: The block height to list objects for (defaults to the latest committed height).
This will give you a list of all objects and any other common prefixes down the tree.
Getting an object
You can use the get
method to retrieve data and download the actual contents. A few options are
available to refine your results:
bytes
: Range request bytes as a dash-separated string (e.g.,"0-99"
gets the first 100 bytes).height
: The height of the bucket to list keys from (defaults to the latest committed height).show_progress
: Visually show the download progress (useful with CLI tools).
Deleting an object
Lastly, since buckets are a fully mutable store, you can delete an object using the delete
method.
It takes similar parameters as adding an object. The default options are generally used, which let
you specify the broadcast mode and gas parameters.
The response will be similar to the add
example above.
Network interactions
You can review the recall_sdk::network
module for more information or check out the network
configuration docs. Utility methods exist on the recall_sdk::network::Network
struct to fetch
network values dynamically, so there's not necessarily a need to hardcode them yourself anywhere.