PATH that starts with stellar-.
How Plugins Work
Plugins are executables (scripts or binaries) that follow a simple naming convention: they must start withstellar-. When you run a command like stellar hello, the CLI first checks for a built-in command. If none is found, it searches for a plugin named stellar-hello in your PATH and executes it if found.
Installing Plugins
You can install plugins that are made available publicly. For example, you can install rs-stellar-strkey using Rust’s cargo:stellar-strkey binary in your ~/.cargo/bin directory. Make sure this directory is in your $PATH for the CLI to detect it.
Security WarningBe careful! Plugins have the same access to your system as the Stellar CLI itself. Only install plugins from sources you trust.
Listing Available Plugins
To list available plugins on your system, use the commandstellar plugin ls:
Creating a New Plugin
To create a plugin, you need an executable file in yourPATH that starts with stellar-. This example shows how to create a simple plugin using bash (works on Unix-based systems or Windows’ WSL).
Step 1: Create the Plugin File
Create a new file namedstellar-hello in a directory that’s in your PATH (for example, ~/.bin):
Step 2: Add the Plugin Code
Add the following content to the file:Step 3: Make It Executable
Make the file executable:Step 4: Verify Installation
If everything is set up correctly (the directory is in yourPATH and the file is executable), you should see your plugin listed:
Step 5: Use Your Plugin
You can now execute your plugin by callingstellar hello:
Plugin Naming and Subcommands
The Stellar CLI automatically searches for plugins when no built-in command matches. This works for both simple commands and subcommands. For example, if you create a plugin namedstellar-contract-bindings-ruby, users can execute it using either:
stellar contract-bindings-ruby(with dashes)stellar contract bindings ruby(with spaces as subcommands)
Troubleshooting
If the Stellar CLI can’t find your plugin, check the following:- Naming: Ensure the file starts with
stellar- - Permissions: Verify it’s executable using
chmod +x - PATH: Check that the plugin’s directory is in your
PATHenvironment variable - Shell: Restart your terminal or reload your shell configuration (e.g., run
source ~/.zshrcorsource ~/.bashrc)