βββββββββββββββββββ ββββββ βββββββ ββββββββββββ ββββββββββββ βββ βββββββββββββββ βββββββββββββββββββ ββββββββββββββββ βββββββββββββ ββββββββββββ βββ ββββββββββββββββ ββββββββββββββ βββ βββββββββββ ββββββββββ ββββββ βββ βββ βββββββ βββ βββ ββββββββββββββ βββ βββββββββββ βββββββββ ββββββββββ βββ βββββββ βββ βββ βββββββββββββββββββ βββ βββββββββββββββββββββββ ββββββ βββ βββ ββββββ βββ βββββββββββββββββββ βββ βββ βββββββ βββββββββββ βββββ βββ βββ ββββββ βββ
This repository is a starter kit for developers who want to build plugins for Cambrian. It provides a simplified workflow to create custom integrations for protocols and services on the SEI blockchain.
- Node.js (v18+)
- npm
- Basic understanding of TypeScript and blockchain concepts
-
Fork this repository:
- Click the "Fork" button in the top right to create your personal copy
-
Clone your forked repository:
git clone https://github.com/YOUR-USERNAME/cambrian-plugin.git cd cambrian-plugin -
Install dependencies:
npm install
Run the provided script to create a new plugin structure:
npm run create-your-plugin your-plugin-nameThis will:
- Create a directory at
src/tools/your-plugin-name/ - Generate an
index.tsfile that exports your plugin functions - Create a template function file (
your-plugin-name.ts) - Update the main tools index to include your plugin
After running the generator, you'll have:
src/tools/your-plugin-name/
βββ index.ts # Exports all functions from your plugin
βββ your-plugin-name.ts # Implementation of your plugin functionality
Edit the generated your-plugin-name.ts file to implement your specific functionality:
import { SeiAgentKit } from "../../index";
/**
* Performs some action with your protocol
* @param agent SeiAgentKit instance
* @param param1 Description of parameter
* @returns Result data or transaction hash
*/
export async function yourPluginName(
agent: SeiAgentKit,
param1: string // Add any parameters your function needs
): Promise<any> {
// Implement your logic here
// Example: Connect to a protocol, make a transaction, etc.
return { success: true, message: "Operation completed" };
}If your plugin needs multiple functions, create new files for each major operation:
touch src/tools/your-plugin-name/anotherFunction.tsThen implement the function and export it in your plugin's index.ts:
// In index.ts
export * from "./your-plugin-name";
export * from "./anotherFunction";- Clear naming: Use descriptive function names that indicate the action
- Input validation: Always validate input parameters
- Error handling: Implement proper error handling with informative messages
- Documentation: Include JSDoc comments for all functions
import { SeiAgentKit } from "../../index";
/**
* Stakes tokens in the protocol
* @param agent SeiAgentKit instance
* @param amount Amount to stake (in full tokens, not micro)
* @returns Transaction hash
*/
export async function stakeTokens(
agent: SeiAgentKit,
amount: number
): Promise<string> {
// 1. Input validation
if (typeof amount !== 'number' || isNaN(amount) || amount <= 0) {
throw new Error(`Invalid amount: ${amount}. Must be a positive number.`);
}
try {
// 2. Your implementation
// ...
// 3. Return result
return "tx_hash_here";
} catch (error) {
// 4. Error handling
console.error(`Error in stakeTokens: ${error}`);
throw error;
}
}Before testing your plugin, you need to set up your environment variables:
-
Copy the example environment file to create your own
.envfile:cp .env.example .env
-
Open the
.envfile and add your SEI wallet private key:SEI_PRIVATE_KEY=your_private_key_hereβ οΈ IMPORTANT: Never commit your.envfile with your private key to version control.
After creating your plugin, you need to integrate it with the SeiAgentKit class. Edit src/agent/index.ts:
// 1. Import your plugin function(s)
import { yourPluginName } from '../tools/your-plugin-name';
export class SeiAgentKit {
// Existing properties and methods...
// 2. Add a method that wraps your plugin function
async yourPluginMethod(param1: string): Promise<any> {
return yourPluginName(this, param1);
}
}Update the test file at test/test.ts to call your new method:
import { SeiAgentKit } from "../src";
import * as dotenv from "dotenv";
dotenv.config();
// Environment validation and setup...
const agent = new SeiAgentKit(
process.env.SEI_PRIVATE_KEY!,
{
OPENAI_API_KEY: "",
},
);
async function main(contract?: string) {
try {
// Test your plugin function
console.log("Testing your plugin...");
const result = await agent.yourPluginMethod("test parameter");
console.log("Result:", result);
} catch (err) {
console.error("Error testing plugin:", err);
return null;
}
}
// Execute the test...Execute your test using the provided npm script:
npm run testThis will:
- Run your test.ts file with tsx
- Execute your plugin function
- Display the results in the console
- Check console logs for any errors
- Verify that your method is correctly importing and calling your plugin function
- Ensure all required parameters are passed correctly
- For blockchain interactions, consider using a testnet environment first
βββββββββββββββββ βββββββββββββββββ βββββββββββββββββ
β Step 1 β β Step 2 β β Step 3 β
β Fork & Clone ββββββΆβ Run Plugin ββββββΆβ Implement β
β Repository β β Generator β β Functions β
βββββββββββββββββ βββββββββββββββββ βββββββββββββββββ
β
βΌ
βββββββββββββββββ βββββββββββββββββ
β Step 5 β β Step 4 β
β Submit Pull βββββββ Test Your β
β Request β β Plugin β
βββββββββββββββββ βββββββββββββββββ
Once you've completed and tested your plugin, submit it for inclusion in the Cambrian ecosystem:
- Push your changes to your fork
- Submit a pull request with a clear description of your plugin's functionality and use cases
Our team will review your submission and handle the integration process. We may reach out for clarification or suggest improvements before merging.
When submitting your pull request, please include:
- A brief description of what your plugin does
- Any dependencies it requires
Building on SEI with Cambrian