| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Stay up to date with changes by joining the official Discord and by keeping an eye on the releases tab.
The stamp create command walks you through purchasing a postage stamp by prompting for just two values: how much data you want to store and how long it should persist.
swarm-cli stamp create
You will be prompted for:
After entering both values, swarm-cli displays a confirmation summary:
You have provided the following parameters: Capacity: 10.737 GB TTL: 4 weeks Cost: 10.4367906627780608 xBZZ Available: 10000.0000000000000000 xBZZ Type: Immutable ? Confirm the purchase Yes Stamp ID: 690ec71e2312cf7cfa1b0d32a34fc20c8c249a8ea6f557cee035354135cefaef
Review the cost, confirm, and the command returns your new Stamp ID. You can then use this ID with the --stamp option in any upload or feed command.
You can use ACT related commands to manage access control for your content. To use and manage ACT, you need to use the access commands.
swarm-cli access init --stamp <postage_batch_id> --list-name <grantee_list_name>swarm-cli access grant --list-name <grantee_list_name> --grantee <grantee_public_key>swarm-cli access revoke --list-name <grantee_list_name> --grantee <grantee_public_key>swarm-cli access listswarm-cli access show --list-name <grantee_list_name>swarm-cli access history --list-name <grantee_list_name>swarm-cli upload <file> --share-with <grantee_list_name>token constructed from the owner's public key and the history address
swarm-cli download <swarm_hash> <file> --access <token>Manage your Bee node and interact with the Swarm network via the CLI
The goal of this project is to handle most of the Swarm operations through CLI at some point in the future.
For the currently supported operations, see the Commands section.
Requires Node.js 18 or higher. It is recommended to use NVM to manage Node.js versions.
Warning! Installing Node.js via package managers (e.g. apt, yum, brew) may not work as expected, as they may install an older version of Node.js.
Install globally:
npm install --global @ethersphere/swarm-cliSee the Development section.
The general usage is to provide a command, optionally a subcommand, then arguments and options.
swarm-cli command [subcommand] <arguments> [options]
Running a command with the --help option prints out the usage of a command.
Running swarm-cli without arguments prints the available commands:
Swarm CLI 2.11.0 - Manage your Bee node and interact with the Swarm network via the CLI █ Usage: swarm-cli COMMAND [OPTIONS] █ Available Groups: pinning Pin, unpin and check pinned chunks identity Import, export and manage keypairs, identities feed Upload, update and view feeds cheque Deposit, withdraw and manage cheques stamp Buy, list and show postage stamps pss Send, receive, or subscribe to PSS messages manifest Operate on manifests utility Utility commands for managing wallets history Get upload history access Share access to your uploaded files/folders Run 'swarm-cli GROUP --help' to see available commands in a group █ Available Commands: reupload Reupload and restamp content on the network upload Upload file to Swarm download Download arbitrary Swarm hash hash Print the Swarm hash of a file status Check Bee status addresses Display the addresses of the Bee node stake Manages nodes stake Run 'swarm-cli COMMAND --help' for more information on a command
Let's say we want to upload our website to Swarm and update a feed to point to the newest version. For updating a feed we would need to sign it with an Ethereum key, so first we need to create one with the identity create command:
swarm-cli identity create
This command will ask for a password. After that a new identity is created (named main). Now we can use this identity to sign updates. It's also possible to import and export Ethereum JSON V3 format identities that works with other apps (e.g. wallets).
Another requirement for uploading to the Swarm network is a valid postage batch, also called a postage stamp or simply a stamp. Stamps need to be purchased with xBZZ tokens. We can use the stamp buy command to take care of this step. The --amount and --depth options alter the capacity of the postage stamp. For example, running stamp buy --amount 1 --depth 20 will get back with a Stamp ID after a while. We will be using that with the --stamp option in commands which upload files, or write feeds.
For uploading to a feed we can use the feed upload command. It expects the path of the folder (or file) we want to upload and as options it expects identity to be provided along with the password that belongs to it, as well as the earlier mentioned stamp.
swarm-cli feed upload path-to-be-uploaded --identity my-identity --password my-secret-password --stamp stamp-id
In this example we are uploading the content of the dist folder. If the uploading was successful the last printed line will contain a Feed Manifest URL. This URL can be opened in the browser. If the uploaded folder contains an index.html file then it will be automatically displayed when visiting the URL.
This URL will stay the same when we upload an updated version of the website. Because of this we can also put this URL into a reverse proxy configuration or use the reference (the hex string after the /bzz/) in an ENS record. There is more information about that in the Bee documentation. The uploaded content can be found on the link in the line starting with URL. This will change every time the content is modified.
Use swarm-cli to upload a single file:
swarm-cli upload README.md
The command above will print a /bzz URL that may be opened in the browser. If the browser is able to handle the file format then the file is displayed, otherwise it will be offered to be downloaded.
swarm-cli also supports uploading folders with the same upload command:
swarm-cli upload build/
This also yields a /bzz URL. If there is an index.html present in the root of the folder, --index-document will be automatically applied by swarm-cli. This option sets which file the browser should open for an empty path. You may also freely set --index-document during upload to change this.
You can pipe data from other commands to swarm-cli using the --stdin option.
curl -L https://picsum.photos/200 | swarm-cli --stdin --stamp [...]
Unlike other upload methods, this results in a /bytes URL, which cannot be displayed by browsers normally. You can still share your hash and others can download it. However, with the --name option, you can give your arbitrary data a file name, and swarm-cli will attempt to determine the suitable content type for your data. Given it is successful, swarm-cli will print a /bzz URL instead of the /bytes URL, which is good to be displayed in browsers. Example:
curl -L https://picsum.photos/200 | swarm-cli --stdin --stamp [...] --name random.jpg
There is also a --content-type option if you want to adjust it manually:
curl -L https://picsum.photos/200 | swarm-cli --stdin --stamp [...] --name random --content-type image/jpeg
Please note that stdin is reserved for the data you are uploading, so interactive features are disabled during this time. Because of that, --stamp must be passed beforehand. You may create an alias for grabbing the ID of the least used postage stamp:
alias st='swarm-cli stamp list --least-used --limit 1 --hide-usage --quiet'
Leveraging the alias above, you can use a shortcut for uploading from stdin:
curl -L https://picsum.photos/200 | swarm-cli --stdin --stamp $(st)
Similarly to curl, you may use the --header or -H option to specify as many additional headers as you want, which will be sent with all requests:
swarm-cli upload README.md -H "Authorization: [...]" -H "X-Custom-Header: Your Value"
swarm-cli has support for autocomplete in bash, zsh and fish. This turns on <tab><tab> suggestions which can complete commands, paths and options for you.
To enable it, you need to install it once via two options:
| Shell | Completion System | Configuration Path |
|---|---|---|
| bash | compdef & compadd OR complete & COMPREPLY | $HOME/.bashrc & $HOME/.bash_profile |
| zsh | compdef & compadd OR complete & COMPREPLY | $HOME/.zshrc |
| fish | complete | $HOME/.config/fish/config.fish |
Warning! If you start a subshell (e.g. running bash from zsh), your SHELL env variable would still be the old value! The generation and completion script cannot detect your shell accurately in that case, so please set SHELL manually. It is generally advised to run --generate-completion first to ensure the shell and the paths are properly detected.
Example:
$ SHELL=zsh $ swarm-cli --generate-completion Your shell is: zsh Found configuration file path: /Users/Swarm/.zshrc Append the completion script below to your configuration file to enable autocomplete. You need to source your configuration, or restart your shell, to load the changes. <script>
As most of the units are specified in wei and PLUR - the smallest denominations of currencies - they are a bit difficult to write out.
To aid this, you may use underscores (_) and K, M, B and T units to make your numbers more comprehensible.
Example:
swarm-cli stamp buy --amount 10M --depth 17 --gas-price 10_000_000_000_000
You may combine the two: 100_000T.
Unless you are running in --quiet mode, some options are not hard-required.
Look for hints in the --help sections. Take the upload command for example:
█ Required Options: --stamp ID of the postage stamp to use [required when quiet][string]
That means, you don't have to provide the postage stamp ID beforehand. Simply running swarm-cli upload <path> will prompt you with an interactive stamp picker:
? Please select a stamp for this action. Stamp ID Utilization (Use arrow keys) ❯ b9d5bb548c2c209cb99cbb27b0bef59b8f0cd3558363e307f45177b5a64ad0c8 (1)
Similarly to Stamp Picker, when an identity is not provided, an interactive picker will be prompted.
Take the command feed upload for example. Albeit it takes quite a lot of options, you can run it with typing as little as feed upload <path>.
swarm-cli will take you through some prompts to interactively specify all required options, such as identity, password of the identity, and the mandatory stamp.
Passing identities is also tolerant to errors, so if you provide one which does not exist, the output will tell you and you can correct it:
The provided identity does not exist. Please select one that exists. ? Please select an identity for this action (Use arrow keys) ❯ main
You may need to pass topics on multiple occasions - for example, when uploading to feeds.
Topics are 32-byte long identifiers, so you need 64 characters to write them out in hexadecimal string format.
You can do that with the --topic or -t option, or alternatively take a shortcut and use a human readable string which will be hashed by swarm-cli for your convenience. It is available via the --topic-string or -T option.
Example:
swarm-cli feed upload [...] -T "Awesome Swarm Website"
This is also indicated in the --help section:
-t --topic 32-byte long identifier in hexadecimal format [hex-string][default all zeroes] -T --topic-string Construct the topic from human readable strings [string] Only one is required: [topic] or [topic-string]
The manifest commands enable low-level operation on manifests. These always require a root manifest reference (hash) argument as the input. Some commands, however, work with subparts of the manifest. A few examples are: downloading only a folder from a manifest, listing files only under a specific path in a manifest, and adding files or folders not to the root of the manifest, but under some path.
These can be achieved by using the bzz://<hash>/<path> scheme in the <address> argument as follows:
List entries under the /command/pss prefix in manifest 1512546a3f4d0fea9f35fa1177486bdfe2bc2536917ad5012ee749604a7b425f
swarm-cli manifest list bzz://1512546a3f4d0fea9f35fa1177486bdfe2bc2536917ad5012ee749604a7b425f/command/pss
Download README.md from manifest 1512546a3f4d0fea9f35fa1177486bdfe2bc2536917ad5012ee749604a7b425f
swarm-cli manifest download bzz://1512546a3f4d0fea9f35fa1177486bdfe2bc2536917ad5012ee749604a7b425f/README.md
Note: The bzz:// protocol can be omitted.
swarm-cli records a local log of your uploads so you can retrieve them later. Without this log, a hash is only shown once - at upload time - and there is no other way to find your prior uploads.
Privacy notice: Upload history is enabled by default. Each entry written to disk includes the timestamp, the resulting Swarm hash, the postage stamp ID, the upload type, and the local file path. If you prefer not to keep any local record of your activity, disable it:
swarm-cli history disableThis will offer to delete the existing history file before disabling tracking.
The history file is stored at ~/.swarm-cli/upload-history.json (on Windows: %APPDATA%\swarm-cli\upload-history.json).
Check whether tracking is active and how many entries exist:
swarm-cli history status
List all recorded uploads:
swarm-cli history list
Inspect a single entry by its index (as shown in history list):
swarm-cli history show <index>
Re-enable tracking after it has been disabled:
swarm-cli history enable
Running swarm-cli with the flag --quiet (or -q for short) disables all interactive features, and makes commands print information in an easily parsable format. The exit code also indicates whether running the command was successful or not. These may be useful for automating tasks both in CI environments and in your terminal too.
Below you will find a few snippets to give an idea how it can be used to compose tasks.
Exit if not all status checks succeed:
swarm-cli status -q || exit 1
Check Bee API connection, compatibility does not matter:
swarm-cli status -q | head -n 1 | grep "^OK"
Grab the first postage stamp:
swarm-cli stamp list --limit 1 --quiet --hide-usage
Grab the least used postage stamp:
swarm-cli stamp list --limit 1 --quiet --hide-usage --least-used
List all postage stamps with zero utilization:
swarm-cli stamp list --max-usage 0 --quiet --hide-usage
Sort postage stamps based on utilization (least utilized comes first):
swarm-cli stamp list --least-used --quiet
Upload a file with the least utilized postage stamp (that has at most 50% usage):
STAMP=$(swarm-cli stamp list --max-usage 50 --least-used --limit 1 --quiet --hide-usage) swarm-cli upload -q README.md --stamp $STAMP
The configuration file is placed in a hidden folder named swarm-cli.
In case of Unix-based systems this config path will be: $HOME/.swarm-cli
On Windows systems: $HOME\AppData\swarm-cli
The configuration file is saved with 600 file permission.
On first run, this configuration will be generated with default values, that you are able to change on your demand under the before mentioned path.
It is possible to set value of particular parameters in different ways.
The assignment priority of how option gets its value in question is the following:
With specific system environment variables you can alter the behaviour of the CLI
After the project has been cloned, the dependencies must be installed. Run the following in the project folder:
$ npm installThen you need to compile the TypeScript code:
$ npm run buildTo make the local swarm-cli files in the dist/ directory available as a global package:
$ npm linkIf all went well you should be able to run swarm-cli.
If npm link fails, or you don't want to install anything, then you can use node dist/src/index.js to run swarm-cli from the checked out directory.
There are some ways you can make this module better:
See what "Maintainer" means here.
| Back | FazBrowse Home | New Git URL |