🌳
Bonsai Docs
  • Introduction
    • Bonsai
    • What is Smart Media?
  • Platform
    • No-code creator studio
    • Guide: Create a post
  • Smart Media
    • Framework for builders
  • Building Smart Media
    • ElizaOS server setup
    • Bonsai Client
    • Templates
  • Guide: Create a Template
  • Client Integrations
    • Showing whether a post is Smart Media
    • Linking to Bonsai for remixes
    • Creating a smart media post
  • Actions
    • Reward Swap
  • Launchpad
    • Overview
    • Getting Started
    • Launchpad Contract
    • Vesting ERC20 Contract
    • Hooks
  • API
    • Tokens
    • Token Balances
    • Buy / Sell Quotes
    • Link your token to a Lens Post & Account
    • Staking data
    • Latest Bonsai posts
  • ElizaOS
    • plugin-bonsai
Powered by GitBook
On this page
  • Installation
  • Exports
  • Guide: How to create content for a Clanker
  • 1. Fetch token information for the clanker
  • 2. Initialize the generation service with a viem Account
  • If you're using Coinbase CDP for wallets, you the wrap a CDP account in a viem Custom Account.
  • 3. Send the generation request
  • 4. Parse the generation data and do whatever you want with it
  1. ElizaOS

plugin-bonsai

This package allows any ElizaOS agent to pay for content generation on Bonsai.

PreviousLatest Bonsai posts

Last updated 5 days ago

The open source package can be found here:

Installation

You can clone/fork the repo and copy the plugin-bonsai/ directory into your packages/ directory.

Exports

These are the main exports available from the package

import { 
    GenerationService, 
    Template, 
    createSmartMedia
} from "@elizaos/plugin-bonsai";
  • GenerationService: create content from a prompt and template

  • Template: the types of templates available

  • createSmartMedia: as an authenticated Lens account, post your content to the Bonsai feed

Guide: How to create content for a Clanker

Here, we'll show an example on how to generate an image using a template on Bonsai, and paying via USDC on Base.

1. Fetch token information for the clanker

const response = await fetch(`https://www.clanker.world/api/get-clanker-by-address?address=${tokenAddress}`, {
  headers: { 'x-api-key': process.env.CLANKER_API_KEY as string }
});

const token = await response.json();

2. Initialize the generation service with a viem Account

This wallet must have USDC on Base to pay for generations

import { GenerationService, Template, GenerationResponse } from "@elizaos/plugin-bonsai";

const account = privateKeyToAccount(process.env.EVM_PRIVATE_KEY as `0x${string}`);
const generationService = new GenerationService(account, "base", process.env.BASE_RPC_URL as string);

3. Send the generation request

const template = Template.IMAGE; // Template.STORY | Template.VIDEO
const subTemplateId = "wall_st_bets"; // "animal_fruit" | "animal_brand"
const prompt = `${token.data.symbol} on the moon`;

// optionally enhance your prompt
const enhancedPrompt = await generationService.enhancePrompt({ prompt, template });

// this will trigger the x402 payment flow before the generation request is processed
const generationResponse = await generationService.create({
    prompt: enhancedPrompt,
    template,
    image: token.data.img_url, // use the token image in the generation
    subTemplateId,
});

4. Parse the generation data and do whatever you want with it

interface GenerationResponse {
  generation: {
    text?: string;
    image?: string; // base64
    video?: {
      buffer: number[],
      mimeType: string,
      size: number
    }
  }
  templateData: any;
}

// parse the generation content and template metadata
const { generation, templateData } = generationResponse as GenerationResponse;

If you simply want the generations, you can copy the contents of

To get an idea of what types of content you can create, check out the .

If you're using Coinbase CDP for wallets, you the .

To get the full list of available templates and sub-templates, you can make a GET request to ⇒

/src/services/generation.ts
Bonsai Studio
ℹ️
wrap a CDP account in a viem Custom Account
https://eliza.onbons.ai/metadata
GitHub - onbonsai/elizaos-plugin-bonsaiGitHub
Logo