Plugins
GOAT plugins are extensions that enable your agent to interact with various blockchain protocols.
Instead of having a generic function to execute arbitrary transactions, plugins provide specific tools for common protocols to reduce the risk of hallucinations.
Key Benefits
- Modularity: Easily add or remove functionalities.
- Reusability: Leverage community-built plugins.
- Customization: Design plugins to meet the unique needs.
Chain Compatibility
Plugins can be EVM/Solana specific or chain-agnostic. If a plugin is chain-specific it will fail to compile when being used with a wallet of a different chain.
See all available plugins here.
Plugin Architecture
Plugins extend the PluginBase
class defined in the core package:
Plugins get passed a WalletClient that can be chain-specific or chain-agnostic.
The WalletClient abstracts the underlying wallet implementation and provides a common interface to:
- Get wallet information
- Sign messages
- Send transactions
This allows plugins to:
- Work with any wallet implementation that implements the WalletClient interface, from key pairs to smart wallets.
- Focus on the specific communication with the protocol without worrying about handling transactions, message signing, etc. for each wallet implementation.
Creating your own GOAT plugin
Using the Plugin Generator
The easiest way to create a new plugin is using the create-plugin
command. This command generates all the necessary files and configuration for a new plugin.
The command will generate:
- A package.json with standard metadata and dependencies
- TypeScript configuration files (tsconfig.json, tsup.config.ts)
- A basic plugin structure in the src directory:
- parameters.ts - Example parameters using Zod schema
- your-plugin-name.service.ts - Service class with an example tool
- your-plugin-name.plugin.ts - Plugin class extending PluginBase
- index.ts - Exports for your plugin
After generating the plugin, you can customize the generated code according to your needs following the guide below.
Manual Creation (Example)
For a detailed understanding of plugin structure, let’s walk through creating a plugin that signs messages with “BAAAA” 🐐 prefixed to them.
Define the plugin interface
Start by defining your plugin extending the PluginBase class.
Since we are just signing messages, we will create a chain-agnostic plugin that works both on EVM and Solana chains.
Add tools to the plugin
There are two ways to add tools to the plugin:
- Using the
@Tool
decorator on our own class - Using the
getTools
andcreateTool
functions to create tools dynamically
Option 1: Using the @Tool
decorator
The @Tool
decorator is a way to create tools in a more declarative way.
You can create a class and decorate its methods with the @Tool
decorator to create tools.
The tool methods will receive the wallet client as the first argument and the parameters as the second argument.
Once we have our class we now need to import it in our plugin class.
Option 2: Using the getTools
and createTool
functions
We will start by implementing the getTools
method in our plugin class.
Inside the method, we will return an array of tools created using the createTool
function.
Add the plugin to the agent
Next steps
- Share your plugin with others!
- Open a PR to add it to the plugins registry in the GOAT SDK.