Bucket
Interact with a bucket contract.
recall bucket
The bucket
subcommand (aliased as bu
) has the following subcommands:
create
: Create a new bucket contract.list
: List buckets by owner in a subnet.add
: Add an object into the bucket.get
: Get an object from the bucket.delete
: Delete an object from the bucket.query
: Query objects in the bucket.metadata
: Set new metadata for an object.
When you create objects, the key
is a custom identifier that, by default, uses the /
delimiter
to create a key-based hierarchy. The value is the data you want to store, which can be a file path.
A best practice is to decide on a key naming convention that makes sense for your data, such as
<namespace>/<id>
or similar. The hierarchical structure of the key allows for easy retrieval of
data by prefixes, which is explained below (see the query
subcommand).
Create
Create a new Bucket contract.
Flag | Required? | Description |
---|---|---|
-p, --private-key | Yes | Wallet private key (ECDSA, secp256k1) for signing transactions. |
--alias | No | Alias for the bucket (shorthand for --metadata "alias=value" ). |
-m, --metadata | No | User-defined metadata. |
--gas-limit | No | Gas limit for the transaction. |
--gas-fee-cap | No | Maximum gas fee for the transaction in attoFIL (1FIL = 10**18 attoFIL). |
--gas-premium | No | Gas premium for the transaction in attoFIL (1FIL = 10**18 attoFIL). |
--sequence | No | Sequence (i.e., nonce) for the transaction. |
Example:
Create a new bucket contract.
Create a new bucket with an alias.
Or create a new bucket with arbitrary metadata.
List buckets
List buckets by owner in a subnet.
You must pass either the --private-key
or --address
flag. An address must be in the delegated
t410
or 0x
format.
recall bucket list --private-key <PRIVATE_KEY>
: Query with a private key (or read from your.env
file).recall bucket list --address <ADDRESS>
: Query at410
or0x
address.
Flag | Required? | Description |
---|---|---|
-p, --private-key | Yes, if no address | Wallet private key (ECDSA, secp256k1) for signing transactions. |
-a, --address | Yes, if no private-key | Account address; the signer's address is used if no address is given. |
--height | No | Query at a specific block height (default: committed ). |
Examples:
Query data contracts by a hex address:
Or at a specific block height:
Add an object
Add an object with a key prefix.
Positionals | Description |
---|---|
<FILE_PATH> | File path to upload. |
You must set the bucket address and object key. The metadata, ttl, and overwrite flags are optional but useful in various scenarios.
Flag | Required? | Description |
---|---|---|
-p, --private-key | Yes | Wallet private key (ECDSA, secp256k1) for signing transactions. |
-a, --address | Yes | Bucket contract address. |
-k, --key | Yes | Key of the object to upload. |
-m, --metadata | No | User-defined metadata. |
--ttl | No | Object time-to-live (TTL) duration. |
-o, --overwrite | No | Overwrite the object if it already exists. |
-b, --broadcast-mode | No | Broadcast mode for the transaction: commit , sync , or async (default: commit ). |
--gas-limit | No | Gas limit for the transaction. |
--gas-fee-cap | No | Maximum gas fee for the transaction in attoFIL (1FIL = 10**18 attoFIL). |
--gas-premium | No | Gas premium for the transaction in attoFIL (1FIL = 10**18 attoFIL). |
--sequence | No | Sequence (i.e., nonce) for the transaction. |
Examples:
Push a file to the bucket—and note the path must be absolute. We can create a file with the following contents:
Add the file to the bucket:
Include metadata in the object along with ttl and overwrite:
Get an object
Get an object from the bucket contract.
Positionals | Description |
---|---|
<KEY> | Key of the object to get. |
Note that when you retrieve the object, it will be written to stdout.
Flag | Required? | Description |
---|---|---|
-a, --address | Yes | Bucket contract address. |
--object-api-url | No | Node Object API URL. |
--range | No | Range of bytes to get from the object (format: "start-end" ; inclusive). Example: "0-99" => first 100 bytes. |
--height | No | Query at a specific block height (default: committed ). |
Examples:
Get an object and write to stdout (default behavior):
Download the output to a file by piping the output:
Or make a range request for a subset of bytes:
Delete an object
Delete an object from the bucket.
Positionals | Description |
---|---|
<KEY> | Key of the object to get. |
Similar to when you add
an object, you can specify gas settings or alter the broadcast mode.
Flag | Required? | Description |
---|---|---|
-p, --private-key | Yes | Wallet private key (ECDSA, secp256k1) for signing transactions. |
-a, --address | Yes | Bucket contract address. |
--object-api-url | No | Node Object API URL. |
-b, --broadcast-mode | No | Broadcast mode for the transaction: commit , sync , or async (default: commit ). |
--gas-limit | No | Gas limit for the transaction. |
--gas-fee-cap | No | Maximum gas fee for the transaction in attoFIL (1FIL = 10**18 attoFIL). |
--gas-premium | No | Gas premium for the transaction in attoFIL (1FIL = 10**18 attoFIL). |
--sequence | No | Sequence (i.e., nonce) for the transaction. |
Example:
Delete an existing object:
Query objects
Query across all objects in the bucket.
Performing a query
lists all keys that match a given prefix up to and including the delimiter.
If the key supplies a delimiter, then the results stop there—essentially, listing subfolders, but
none lower. Think of it as you would when listing files in a directory. If you list the contents of
a folder, you'll see all subfolders, but you won't see the contents of one of those subfolders.
For example, if you have the keys hello/world
, hello/data
, and hello/world/child
, and you
query for the prefix hello/
, you will get the objects at hello/world
and hello/data
but not
hello/world/child
since its "nested" under the prefix hello/world/
(note: inclusive of the /
at the end).
Flag | Required? | Description |
---|---|---|
-a, --address | Yes | Bucket contract address. |
-p, --prefix | No | The prefix to filter objects by (defaults to empty string). |
-d, --delimiter | No | The delimiter used to define object hierarchy (default: / ). |
-o, --offset | No | The offset from which to start listing objects (default: 0 ) |
-l, --limit | No | The maximum number of objects to list, where 0 indicates max (10k)(default: 0 ) |
--height | No | Query at a specific block height (default: committed ). |
Examples:
Get all objects but without any filtering. Since the object keys have a delimiter included, you'll
see the common prefix hello/
, but no objects are listed since the "root" is the prefix:
Get all objects under a specific prefix. In this case, the response will include all objects under
the hello/
prefix, and since there are no "child" objects that match hello/
(e.g.,
hello/world/child
), the common_prefixes
array will be empty, so you know there are no more
sub-objects to list:
Get objects and filter by a prefix from a starting key and a limit. In the example above, lets say a
"hello/data"
object was created after "hello/world"
. When we query the bucket, it will be the
first object listed since we're offsetting and starting from the "hello/data"
object. We'll also
include the rest of the optional flags for demonstration purposes:
Add metadata to an object
Add metadata to an existing object.
Flag | Required? | Description |
---|---|---|
-a, --address | Yes | Bucket contract address. |
-k, --key | Yes | Key of the object to add metadata to. |
-m, --metadata | Yes | Metadata to add to the object. |
Example:
- Add metadata to an existing object: