Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

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

Are you part of a startup agent team building with Virtuals? You may be eligible for free credits through Crossmint's Startup Program! Apply now to unlock exclusive startup benefits — and don’t forget to mention you’re part of a startup building with Virtuals when you get in touch.

Installation

To install the plugin, use npm or yarn:

npm install @virtuals-protocol/game-on-chain-actions-plugin

or

yarn add @virtuals-protocol/game-on-chain-actions-plugin

Usage

  1. Import the getOnChainActionsWorker function from the plugin:
import { getOnChainActionsWorker } from "@virtuals-protocol/game-on-chain-actions-plugin";
  1. 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,
});
  1. 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,
    }),
  ],
});
  1. 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],
});
  1. Initialize and run the agent:
(async () => {
  await agent.init();

  while (true) {
    await agent.step({
      verbose: true,
    });
  }
})();