@virtuals-protocol/game-on-chain-actions-plugin
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

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-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,
    });
  }
})();

Readme

Keywords

none

Package Sidebar

Install

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

Weekly Downloads

1

Version

0.1.1

License

MIT

Unpacked Size

9.91 kB

Total Files

6

Last publish

Collaborators

  • vituals
  • zuhwa
  • jsoh0118