forked from elizaOS/eliza
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request elizaOS#898 from goat-sdk/plugin-secrets
chore: pass env variables when setting up GOAT and update GOAT readme
- Loading branch information
Showing
6 changed files
with
131 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,39 @@ | ||
# Goat Plugin | ||
Example plugin setup of how you can integrate [Goat](https://ohmygoat.dev/) tools and plugins with Eliza. | ||
|
||
Adds onchain capabilities to your agent to send and check balances of ETH and USDC. Add all the capabilities you need by adding more plugins! | ||
|
||
## Setup | ||
1. Configure your wallet (key pair, smart wallet, etc. see all available wallets at [https://ohmygoat.dev/wallets](https://ohmygoat.dev/wallets)) | ||
2. Add the plugins you need (uniswap, zora, polymarket, etc. see all available plugins at [https://ohmygoat.dev/chains-wallets-plugins](https://ohmygoat.dev/chains-wallets-plugins)) | ||
3. Select a chain (see all available chains at [https://ohmygoat.dev/chains](https://ohmygoat.dev/chains)) | ||
4. Import and add the plugin to your Eliza agent | ||
5. Build the project | ||
6. Add the necessary environment variables to set up your wallet and plugins | ||
# GOAT Plugin | ||
[GOAT](https://ohmygoat.dev/) 🐐 (Great Onchain Agent Toolkit) is an open-source framework for adding blockchain tools such as wallets, being able to hold or trade tokens, or interacting with blockchain smart contracts, to your AI agent. | ||
|
||
This plugin integrates GOAT with Eliza, giving your agent the ability to interact with many different protocols. The current setup adds onchain capabilities to your agent to send and check balances of ETH and USDC. Add all the capabilities you need by adding more plugins (read below for more information)! | ||
|
||
## Configure GOAT for your use case | ||
1. Configure the chain you want to use by updating the `wallet.ts` file (see all available chains at [https://ohmygoat.dev/chains](https://ohmygoat.dev/chains)) | ||
2. Add the plugins you need to your `getOnChainActions` function (uniswap, polymarket, etc. see all available plugins at [https://ohmygoat.dev/chains-wallets-plugins](https://ohmygoat.dev/chains-wallets-plugins)) | ||
3. Build the project running `pnpm build` | ||
4. Add the necessary environment variables to set up your wallet and plugins | ||
5. Run your agent! | ||
|
||
## Common Issues | ||
1. **Agent not executing an action**: | ||
- If you are also using the EVM Plugin, sometimes the agent might confuse the action name with an EVM Plugin action name instead of the GOAT Plugin action. Removing the EVM Plugin should fix this issue. There is no need for you to use both plugins at the same time. | ||
- If you are using Trump as a character it might be tricky to get them to perform any action since the character is full of prompts that aim to change the topic of the conversation. To fix this try using a different character or create your own with prompts that are more suitable to what the agent is supposed to do. | ||
|
||
## Plugins | ||
GOAT itself has several plugins for interacting with different protocols such as Polymarket, Uniswap, and more. (see all available plugins at [https://ohmygoat.dev/chains-wallets-plugins](https://ohmygoat.dev/chains-wallets-plugins)) | ||
|
||
You can easily add them by installing them and adding them to the `getOnChainActions` function: | ||
|
||
```typescript | ||
const tools = getOnChainActions({ | ||
wallet: walletClient, | ||
plugins: [ | ||
sendETH(), | ||
erc20({ tokens: [USDC, PEPE] }), | ||
polymarket(), | ||
uniswap(), | ||
// ... | ||
], | ||
}) | ||
``` | ||
|
||
## Wallets | ||
GOAT supports many different wallets from key pairs to [Crossmint Smart Wallets](https://docs.crossmint.com/wallets/smart-wallets/overview) and Coinbase. | ||
|
||
Read more about wallets at [https://ohmygoat.dev/wallets](https://ohmygoat.dev/wallets). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,31 @@ | ||
import type { Plugin } from '@ai16z/eliza' | ||
import { getOnChainActions } from './actions'; | ||
import { erc20, USDC } from '@goat-sdk/plugin-erc20'; | ||
import { chain, getWalletClient, walletProvider } from './provider'; | ||
import { sendETH } from '@goat-sdk/core'; | ||
import type { Plugin } from "@ai16z/eliza"; | ||
import { getOnChainActions } from "./actions"; | ||
import { erc20, USDC } from "@goat-sdk/plugin-erc20"; | ||
import { sendETH } from "@goat-sdk/core"; | ||
import { getWalletClient, getWalletProvider } from "./wallet"; | ||
|
||
export const goatPlugin: Plugin = { | ||
name: "[GOAT] Onchain Actions", | ||
description: "Base integration plugin", | ||
providers: [walletProvider], | ||
evaluators: [], | ||
services: [], | ||
actions: [ | ||
...(await getOnChainActions({ | ||
getWalletClient, | ||
// Add plugins here based on what actions you want to use | ||
// See all available plugins at https://ohmygoat.dev/chains-wallets-plugins#plugins | ||
plugins: [sendETH(), erc20({ tokens: [USDC] })], | ||
chain: { | ||
type: "evm", | ||
id: chain.id, | ||
}, | ||
})), | ||
], | ||
}; | ||
async function createGoatPlugin( | ||
getSetting: (key: string) => string | undefined | ||
): Promise<Plugin> { | ||
const walletClient = getWalletClient(getSetting); | ||
const actions = await getOnChainActions({ | ||
wallet: walletClient, | ||
// Add plugins here based on what actions you want to use | ||
// See all available plugins at https://ohmygoat.dev/chains-wallets-plugins#plugins | ||
plugins: [ | ||
sendETH(), | ||
erc20({ tokens: [USDC] }), | ||
], | ||
}); | ||
|
||
export default goatPlugin | ||
return { | ||
name: "[GOAT] Onchain Actions", | ||
description: "Base integration plugin", | ||
providers: [getWalletProvider(walletClient)], | ||
evaluators: [], | ||
services: [], | ||
actions: actions, | ||
}; | ||
} | ||
|
||
export default createGoatPlugin; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { WalletClient } from "@goat-sdk/core"; | ||
import { viem } from "@goat-sdk/wallet-viem"; | ||
import { createWalletClient, http } from "viem"; | ||
import { privateKeyToAccount } from "viem/accounts"; | ||
import { base } from "viem/chains"; | ||
|
||
// Add the chain you want to use, remember to update also | ||
// the EVM_PROVIDER_URL to the correct one for the chain | ||
export const chain = base; | ||
|
||
export function getWalletClient( | ||
getSetting: (key: string) => string | undefined | ||
) { | ||
const privateKey = getSetting("EVM_PRIVATE_KEY"); | ||
if (!privateKey) return null; | ||
|
||
const provider = getSetting("EVM_PROVIDER_URL"); | ||
if (!provider) throw new Error("EVM_PROVIDER_URL not configured"); | ||
|
||
const wallet = createWalletClient({ | ||
account: privateKeyToAccount(privateKey as `0x${string}`), | ||
chain: chain, | ||
transport: http(provider), | ||
}); | ||
|
||
return viem(wallet); | ||
} | ||
|
||
export function getWalletProvider(walletClient: WalletClient) { | ||
return { | ||
async get(): Promise<string | null> { | ||
try { | ||
const address = walletClient.getAddress(); | ||
const balance = await walletClient.balanceOf(address); | ||
return `EVM Wallet Address: ${address}\nBalance: ${balance} ETH`; | ||
} catch (error) { | ||
console.error("Error in EVM wallet provider:", error); | ||
return null; | ||
} | ||
}, | ||
}; | ||
} |