@virtuals-protocol/game-coingecko-maop-plugin
v0.1.0
Published
coingecko plugin for GAME SDK under questflow MAOP
Downloads
3
Readme
Coingecko Plugin for Virtuals Game
The Coingecko plugin seamlessly empowers G.A.M.E agents with cryptocurrency data fetching capabilities using the Coingecko API, enabling the retrieval of current market data without introducing any additional complexity.
Features
- Fetch current cryptocurrency prices
- Retrieve market data for various cryptocurrencies
- Built-in error handling and status tracking
Available Functions
fetchPrice: Retrieves the current price of a specified cryptocurrency
Installation
To install the plugin, use npm or yarn:
npm install @virtuals-protocol/game-coingecko-maop-pluginor
yarn add @virtuals-protocol/game-coingecko-maop-pluginUsage
Importing the Plugin
First, import the CoingeckoMAOPPlugin class from the plugin:
import CoingeckoMAOPPlugin from "@virtuals-protocol/game-coingecko-maop-plugin";Setup environment variables
Set the following environment variables:
COINGECKO_MAOP_API_KEY: Create an API key by contact questflow.
Creating a Worker
Create a worker with the necessary questflow maop API client config:
const coingeckoMAOPPlugin = new CoingeckoMAOPPlugin({
apiClientConfig: {
apiKey: process.env.MAOP_GAME_PLUGIN_API_KEY,
},
});Creating an Agent
Create an agent and add the worker to it:
import { GameAgent } from "@virtuals-protocol/game";
const agent = new GameAgent("GAME_API_KEY", {
name: "Cryptocurrency Data Worker",
goal: "Fetch the current price of Bitcoin.",
description:
"You are an AI agent specialized in fetching cryptocurrency data. You can retrieve current market data using the Coingecko API.",
workers: [coingeckoMAOPPlugin.getWorker({})],
});Running the Agent
Initialize and run the agent:
(async () => {
// Optional: Set up logging
agent.setLogger((agent, message) => {
console.log(`-----[${agent.name}]-----`);
console.log(message);
console.log("\n");
});
await agent.init();
while (true) {
await agent.step({
verbose: true,
});
}
})();Example Worker Usage
Here's a simple example of using the worker directly:
const worker = coingeckoMAOPPlugin.getWorker({});
// The worker will automatically use the fetch_price function
// to retrieve the current price of Bitcoin
worker.run("retrieve the current price of Bitcoin");Configuration Options
The plugin accepts the following configuration options when initializing:
interface ICoingeckoMAOPPluginOptions {
id?: string; // Custom worker ID
name?: string; // Custom worker name
description?: string; // Custom worker description
apiClientConfig: {
apiKey?: string; // Questflow maop API key
baseApiUrl?: string; // Custom API endpoint (optional)
};
}Development
- Clone the repository
- Install dependencies:
npm install- Set up environment variables:
export GAME_API_KEY="your-game-api-key"
export MAOP_GAME_PLUGIN_API_KEY="your-maop-game-plugin-api-key"- Build the plugin:
npm run tsup- Run the example:
ts-node examples/example.tsor
npm run example- Run special function example:
npm run coinDataByID