Read & write data
Learn how to read and write data to a data source.
Once you've created a data source, you have full control over it. By default, only the owner of a bucket can write to it, but anyone can read from it if they know the contract address.
Writing data
To write data to a bucket, you can use the recall bucket add
command. Executing the write
operation will send the data to the network in two steps:
- Stage the data with the validator whose RPCs / APIs it is calling
- Finalize the data onchain with a transaction, which creates the key-value mapping in the bucket
Note that every object has a default TTL of 24 hours (86400 seconds). If you need a longer
retention period, you can use the --ttl
flag to set a custom TTL (in seconds).
Once executed, the output will include the object's hash and size, along with the actual transaction:
Sending the data should only take a second or two, and then the data will be available to read from
the bucket immediately. You'll notice the rzghyg4z3p6vbz5jkgc75lk64fci7kieul65o6hk6xznx7lctkmq
value was logged in the response—this is the blake3 hash of the data. Hashes uniquely identify the
data's contents, so you can be sure that the data hasn't changed.
Metadata
You can also add metadata to the object. This is optional, but it can be useful for storing information about the data you're storing.
It's also possible to update an object's metadata after it's been stored.
All Recall tools (CLI, SDKs, etc.) attempt to infer the data type and automatically attach the
content-type
metadata, which falls back to application/octet-stream
. For example, if you pass a
png
file, it will be inferred as image/png
.
Reading data
To read data from a bucket, you can use the recall bucket get
command by providing the bucket
address and desired key:
The contents are returned in terms of its original size and format.
The download speed will depend on both your connection speed and the validator's connection speed. Recall has high requirements for the hardware and bandwidth of the validator nodes, so you can expect fast downloads.
Alternatively, if you simply want to see which objects are available for download, the query
command can be used:
This will return a list of all the objects in the bucket, along with their size and hash.