@virtuals-protocol/game-on-chain-actions-plugin
v0.1.1
Published
The onchain actions plugin allows your GAME agents to execute onchain actions such as swaps, transfers, staking, etc. all by leveraging the [GOAT SDK](https://github.com/goat-sdk/goat).
Readme
Onchain Actions Plugin for Virtuals Game
The onchain actions plugin allows your GAME agents to execute onchain actions such as swaps, transfers, staking, etc. all by leveraging the GOAT SDK.
Supports:
- Any chain, from EVM, to Solana, to Sui, etc.
- Any wallet type, from key pairs to smart wallets from Crossmint, etc.
- More than +200 onchain tools from the GOAT SDK, see all available tools here
Installation
To install the plugin, use npm or yarn:
npm install @virtuals-protocol/game-on-chain-actions-pluginor
yarn add @virtuals-protocol/game-on-chain-actions-pluginUsage
- Import the
getOnChainActionsWorkerfunction from the plugin:
import { getOnChainActionsWorker } from "@virtuals-protocol/game-on-chain-actions-plugin";- Setup up a wallet
Set up a wallet for the chain you want to use
Example for EVM
import { createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
const account = privateKeyToAccount(
process.env.WALLET_PRIVATE_KEY as `0x${string}`
);
const walletClient = createWalletClient({
account: account,
transport: http(process.env.RPC_PROVIDER_URL),
chain: base,
});- Create the worker adding the wallet and the plugins you want to use
const onChainActionsWorker = await getOnChainActionsWorker({
wallet: viem(walletClient),
plugins: [
sendETH(),
erc20({ tokens: [USDC, PEPE] }),
uniswap({
baseUrl: process.env.UNISWAP_BASE_URL as string,
apiKey: process.env.UNISWAP_API_KEY as string,
}),
],
});- Create an agent and add the worker to it:
import { GameAgent } from "@virtuals-protocol/game";
const agent = new GameAgent("GAME_API_KEY", {
name: "Onchain Actions Agent",
goal: "Swap 0.01 USDC to PEPE",
description: "An agent that executes onchain actions",
workers: [onChainActionsWorker],
});- Initialize and run the agent:
(async () => {
await agent.init();
while (true) {
await agent.step({
verbose: true,
});
}
})();