Skip to main content
This page shows you how to give an actor files to work from, by setting up a volume and building an actor that answers from a document in it. An actor’s files live in volumes: named, durable storage that you create and own. Actor code itself never opens a file. The work an actor starts does that for it: an off-chain function or a runner job gets the volumes the actor names, mounted as ordinary folders, while it runs.

Public and private volumes

You pick public or private when you create a volume, and can’t change it. Either way, a volume pays for its own storage from money you put in it. Your keys and your data says who can see what.

1. Create a volume and add a file

First connect your wallet to storage, once. It asks for a passphrase to protect the storage key it creates:
Output
Then create the volume and upload a file:
Output
volume create creates the volume and pays for its first stretch of storage from your wallet, and put <volume> <local file> <path in the volume> uploads a file. cowboy cbfs cat handbook faq/refunds.md prints one file back. When the volume needs more storage, cowboy cbfs volume deposit handbook --amount 1 adds 1 CBY. Leave out --public to create a private volume. An actor can use your private volume only after you allow it:
Output

2. Read it from an off-chain function

An off-chain function is your own Python, run in a container, and cowboy.toml declares the volumes it gets. Runner jobs can take volumes too, with volumes= (reference), but this page uses a function.
Output
The last line removes the starter function and tests you won’t use. Replace cowboy.toml with the following, using your wallet’s address as owner:
name and owner say which volume: the volume called handbook that this address owns. A volume declared this way is mounted read-only. files lists the files cowboy run downloads for a local run, and doesn’t limit what the deployed function can read. Write the function in offchain/handbook.py:
Each volume appears as a folder with the volume’s name, under /mnt/volumes. A local run sets COWBOY_VOLUME_ROOT to a folder of its own instead. Export the function in offchain/__init__.py:
Replace actors/reader/main.py with the actor that calls it:
Output
cowboy check also prints how one call is priced. The actor’s balance pays for each call.

3. Test it

Test the function with a folder standing in for the volume, in offchain/tests/test_handbook.py:
Output
Then run the actor with the function’s answer stubbed, so no volume is needed:
Output
The CBOR reading is the handler’s answer. Without --stub, cowboy run downloads the file from the real volume, so it needs a network.

Next