mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-05-15 23:26:46 +00:00
Update guides content and code snippets (#80)
# Pull Request Description ## Changes Made This PR adds updates to the guides: > `test_it_out.md` - Fixed outdated code examples > `add_your_own_tool.md` - Prepend filename hints to code snippets (for easier navigation) - Add more code snippets for agent usage and custom tool usage
This commit is contained in:
@@ -18,7 +18,7 @@ Extending the **Solana Agent Kit** with custom tools allows you to add specializ
|
||||
Create a new TypeScript file in the `src/tools/` directory for your tool (e.g., `custom_tool.ts`).
|
||||
|
||||
### 2. Implement the Tool Class
|
||||
|
||||
> `src/langchain/index.ts`
|
||||
```typescript:src/langchain/index.ts
|
||||
import { Tool } from "langchain/tools";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
@@ -51,7 +51,7 @@ export class CustomTool extends Tool {
|
||||
```
|
||||
|
||||
### 3. Add Supporting Functions to SolanaAgentKit
|
||||
|
||||
> `src/agent/index.ts`
|
||||
```typescript:src/agent/index.ts
|
||||
export class SolanaAgentKit {
|
||||
// ... existing code ...
|
||||
@@ -64,7 +64,7 @@ export class SolanaAgentKit {
|
||||
```
|
||||
|
||||
### 4. Export the Tool
|
||||
|
||||
> `src/tools/index.ts`
|
||||
```typescript:src/tools/index.ts
|
||||
export * from "./request_faucet_funds";
|
||||
export * from "./deploy_token";
|
||||
@@ -72,7 +72,7 @@ export * from "./custom_tool"; // Add your new tool
|
||||
```
|
||||
|
||||
### 5. Integrate with Agent
|
||||
|
||||
> `src/langchain/index.ts`
|
||||
```typescript:src/langchain/index.ts
|
||||
import { CustomTool } from "../tools/custom_tool";
|
||||
|
||||
@@ -104,6 +104,10 @@ if (customTool) {
|
||||
const result = await customTool._call("your-input");
|
||||
console.log(result);
|
||||
}
|
||||
|
||||
// or alternatively
|
||||
const result = await agent.customFunction("your-input"); // assuming you have a `customFunction` method in SolanaAgentKit
|
||||
console.log(result);
|
||||
```
|
||||
|
||||
## Best Practices
|
||||
@@ -117,7 +121,7 @@ if (customTool) {
|
||||
## Example: Token Price Fetching Tool
|
||||
|
||||
Here's a complete example of implementing a tool to fetch token prices:
|
||||
|
||||
> `src/tools/fetch_token_price.ts`
|
||||
```typescript:src/tools/fetch_token_price.ts
|
||||
import { Tool } from "langchain/tools";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
@@ -150,7 +154,7 @@ export class FetchTokenPriceTool extends Tool {
|
||||
```
|
||||
|
||||
Add the supporting function to SolanaAgentKit:
|
||||
|
||||
> `src/agent/index.ts`
|
||||
```typescript:src/agent/index.ts
|
||||
export class SolanaAgentKit {
|
||||
async getTokenPrice(tokenSymbol: string): Promise<number> {
|
||||
@@ -170,6 +174,21 @@ export class SolanaAgentKit {
|
||||
}
|
||||
```
|
||||
|
||||
Then it can be used as such:
|
||||
|
||||
```typescript
|
||||
import { SolanaAgentKit } from "solana-agent-kit";
|
||||
|
||||
const agent = new SolanaAgentKit(
|
||||
"your-wallet-private-key-as-base58",
|
||||
"https://api.mainnet-beta.solana.com",
|
||||
"your-openai-api-key"
|
||||
);
|
||||
|
||||
const result = await agent.getTokenPrice("SOL");
|
||||
console.log(result);
|
||||
```
|
||||
|
||||
## Need Help?
|
||||
|
||||
If you encounter any issues while implementing your custom tool:
|
||||
|
||||
@@ -49,12 +49,12 @@ The project includes a test script located at `test/index.ts`. To execute the te
|
||||
|
||||
### Token Deployment
|
||||
```typescript
|
||||
import { deploy_token } from "solana-agent-kit";
|
||||
import { SolanaAgentKit } from "solana-agent-kit";
|
||||
|
||||
const result = await deploy_token(
|
||||
agent,
|
||||
9, // decimals
|
||||
1000000 // initial supply
|
||||
const agent = new SolanaAgentKit("your_private_key");
|
||||
|
||||
const result = await agent.deployToken(
|
||||
9, // decimals
|
||||
);
|
||||
|
||||
console.log("Token Mint Address:", result.mint.toString());
|
||||
@@ -62,9 +62,11 @@ console.log("Token Mint Address:", result.mint.toString());
|
||||
|
||||
### NFT Collection Creation
|
||||
```typescript
|
||||
import { deploy_collection } from "solana-agent-kit";
|
||||
import { SolanaAgentKit } from "solana-agent-kit";
|
||||
|
||||
const collection = await deploy_collection(agent, {
|
||||
const agent = new SolanaAgentKit("your_private_key");
|
||||
|
||||
const collection = await agent.deployCollection({
|
||||
name: "My NFT Collection",
|
||||
uri: "https://arweave.net/metadata.json",
|
||||
royaltyBasisPoints: 500, // 5%
|
||||
|
||||
Reference in New Issue
Block a user