Skip to main content

Overview

The Web3 Runtime is a lightweight execution engine for Web3 Blueprint nodes. It handles wallet interactions, transaction signing, and integrates with Solana programs including Pump.fun, Metaplex, and SPL Token.

Types

Web3RuntimeContext

interface Web3RuntimeContext {
    connection: Connection;
    publicKey: PublicKey;
    signTransaction: (tx: Transaction) => Promise<Transaction>;
    signAllTransactions?: (txs: Transaction[]) => Promise<Transaction[]>;
}
Context object containing Solana connection and wallet signing functions.

TokenLaunchResult

interface TokenLaunchResult {
    tokenMint: string;
    txHash: string;
}

BuyResult

interface BuyResult {
    tokensReceived: number;
    txHash: string;
}

SellResult

interface SellResult {
    solReceived: number;
    txHash: string;
}

MintNFTResult

interface MintNFTResult {
    mintAddress: string;
    txHash: string;
}

BalanceResult

interface BalanceResult {
    balance: number;
}

TokenPriceResult

interface TokenPriceResult {
    priceInSol: number;
    marketCap: number;
}

Token Functions (Pump.fun)

executeTokenLaunch

async function executeTokenLaunch(
    ctx: Web3RuntimeContext,
    name: string,
    symbol: string,
    imageUri: string
): Promise<TokenLaunchResult>
Launches a token on the Pump.fun bonding curve.
ctx
Web3RuntimeContext
required
Runtime context with connection and wallet
name
string
required
Token name (e.g., “My Game Token”)
symbol
string
required
Token symbol (e.g., “GAME”)
imageUri
string
required
IPFS or Arweave URI for token image
tokenMint
string
The created token’s mint address
txHash
string
Transaction signature
Example:
import { executeTokenLaunch } from '@/lib/web3Runtime';
import { useWallet } from '@solana/wallet-adapter-react';
import { Connection } from '@solana/web3.js';

function LaunchToken() {
  const { publicKey, signTransaction } = useWallet();
  const connection = new Connection('https://api.mainnet-beta.solana.com');
  
  const handleLaunch = async () => {
    if (!publicKey || !signTransaction) return;
    
    const result = await executeTokenLaunch(
      { connection, publicKey, signTransaction },
      'My Game Token',
      'GAME',
      'https://arweave.net/...'
    );
    
    console.log(`Token launched: ${result.tokenMint}`);
    console.log(`Transaction: ${result.txHash}`);
  };
  
  return <button onClick={handleLaunch}>Launch Token</button>;
}

executeBuyToken

async function executeBuyToken(
    ctx: Web3RuntimeContext,
    tokenMint: string,
    solAmount: number,
    slippage: number = 1
): Promise<BuyResult>
Buys tokens on the Pump.fun bonding curve.
ctx
Web3RuntimeContext
required
Runtime context with connection and wallet
tokenMint
string
required
Token mint address to buy
solAmount
number
required
Amount of SOL to spend
slippage
number
default:"1"
Slippage tolerance percentage (default: 1%)
tokensReceived
number
Amount of tokens received
txHash
string
Transaction signature
Example:
import { executeBuyToken } from '@/lib/web3Runtime';

const result = await executeBuyToken(
  ctx,
  'TokenMintAddress...',
  0.1, // 0.1 SOL
  1.5  // 1.5% slippage
);

console.log(`Received ${result.tokensReceived} tokens`);

executeSellToken

async function executeSellToken(
    ctx: Web3RuntimeContext,
    tokenMint: string,
    tokenAmount: number,
    slippage: number = 1
): Promise<SellResult>
Sells tokens on the Pump.fun bonding curve.
ctx
Web3RuntimeContext
required
Runtime context with connection and wallet
tokenMint
string
required
Token mint address to sell
tokenAmount
number
required
Amount of tokens to sell
slippage
number
default:"1"
Slippage tolerance percentage
solReceived
number
Amount of SOL received
txHash
string
Transaction signature
Example:
import { executeSellToken } from '@/lib/web3Runtime';

const result = await executeSellToken(
  ctx,
  'TokenMintAddress...',
  1000000, // Sell 1M tokens
  2        // 2% slippage
);

console.log(`Received ${result.solReceived} SOL`);

NFT Functions (Metaplex)

executeMintNFT

async function executeMintNFT(
    ctx: Web3RuntimeContext,
    name: string,
    imageUri: string,
    attributes?: Record<string, string>
): Promise<MintNFTResult>
Mints an NFT using Metaplex.
ctx
Web3RuntimeContext
required
Runtime context with connection and wallet
name
string
required
NFT name
imageUri
string
required
IPFS or Arweave URI for NFT image
attributes
Record<string, string>
Optional NFT attributes/metadata
mintAddress
string
The created NFT’s mint address
txHash
string
Transaction signature
Example:
import { executeMintNFT } from '@/lib/web3Runtime';

const result = await executeMintNFT(
  ctx,
  'Victory Badge',
  'https://arweave.net/badge.png',
  { level: '10', achievement: 'first_win' }
);

console.log(`NFT minted: ${result.mintAddress}`);

Gate Functions

executeTokenGate

async function executeTokenGate(
    ctx: Web3RuntimeContext,
    tokenMint: string,
    minBalance: number
): Promise<{ hasAccess: boolean; balance: number }>
Checks if a player holds enough tokens to access gated content.
ctx
Web3RuntimeContext
required
Runtime context with connection and wallet
tokenMint
string
required
Token mint address to check
minBalance
number
required
Minimum token balance required
hasAccess
boolean
Whether the player has sufficient tokens
balance
number
Player’s current token balance
Example:
import { executeTokenGate } from '@/lib/web3Runtime';

const { hasAccess, balance } = await executeTokenGate(
  ctx,
  'TokenMintAddress...',
  1000 // Require 1000 tokens
);

if (hasAccess) {
  console.log('Access granted!');
} else {
  console.log(`Need ${1000 - balance} more tokens`);
}

Balance Functions

executeCheckBalance

async function executeCheckBalance(
    ctx: Web3RuntimeContext,
    tokenMint?: string
): Promise<BalanceResult>
Gets the SOL or token balance for the connected wallet.
ctx
Web3RuntimeContext
required
Runtime context with connection and wallet
tokenMint
string
Token mint address to check. If omitted or ‘SOL’, returns SOL balance
balance
number
Balance in SOL or tokens
Example:
import { executeCheckBalance } from '@/lib/web3Runtime';

// Check SOL balance
const solBalance = await executeCheckBalance(ctx);
console.log(`SOL: ${solBalance.balance}`);

// Check token balance
const tokenBalance = await executeCheckBalance(ctx, 'TokenMintAddress...');
console.log(`Tokens: ${tokenBalance.balance}`);

Transfer Functions

executeSendSOL

async function executeSendSOL(
    ctx: Web3RuntimeContext,
    recipient: string,
    amount: number
): Promise<{ txHash: string }>
Sends SOL to another wallet.
ctx
Web3RuntimeContext
required
Runtime context with connection and wallet
recipient
string
required
Recipient wallet address
amount
number
required
Amount of SOL to send
txHash
string
Transaction signature
Example:
import { executeSendSOL } from '@/lib/web3Runtime';

const result = await executeSendSOL(
  ctx,
  'RecipientPublicKey...',
  0.5 // Send 0.5 SOL
);

console.log(`Sent! TX: ${result.txHash}`);

Price Functions

executeGetTokenPrice

async function executeGetTokenPrice(
    ctx: Web3RuntimeContext,
    tokenMint: string
): Promise<TokenPriceResult>
Queries the bonding curve price from Pump.fun.
ctx
Web3RuntimeContext
required
Runtime context with connection and wallet
tokenMint
string
required
Token mint address
priceInSol
number
Current price in SOL
marketCap
number
Current market cap
Example:
import { executeGetTokenPrice } from '@/lib/web3Runtime';

const price = await executeGetTokenPrice(ctx, 'TokenMintAddress...');
console.log(`Price: ${price.priceInSol} SOL`);
console.log(`Market Cap: ${price.marketCap}`);

Node Executor Map

WEB3_NODE_EXECUTORS

const WEB3_NODE_EXECUTORS: Record<string, (...args: any[]) => Promise<any>>
Maps Blueprint node labels to their executor functions. Available Nodes:
  • 🚀 Launch Token (Pump.fun)executeTokenLaunch
  • 💰 Buy Token (Pump.fun)executeBuyToken
  • 💸 Sell Token (Pump.fun)executeSellToken
  • 🎨 Mint NFTexecuteMintNFT
  • 🔐 Token GateexecuteTokenGate
  • 💎 Check BalanceexecuteCheckBalance
  • ⬡ Send SOLexecuteSendSOL
  • 📊 Get Token PriceexecuteGetTokenPrice
Example:
import { WEB3_NODE_EXECUTORS } from '@/lib/web3Runtime';

// Execute a node by label
const nodeLabel = '🚀 Launch Token (Pump.fun)';
const executor = WEB3_NODE_EXECUTORS[nodeLabel];

if (executor) {
  const result = await executor(ctx, 'My Token', 'TKN', 'https://...');
  console.log(result);
}

Complete Game Integration

import { 
  Web3RuntimeContext, 
  executeTokenGate, 
  executeMintNFT 
} from '@/lib/web3Runtime';
import { useWallet } from '@solana/wallet-adapter-react';
import { Connection } from '@solana/web3.js';

function Web3Game() {
  const { publicKey, signTransaction } = useWallet();
  const connection = new Connection('https://api.mainnet-beta.solana.com');
  
  const handleGameWin = async () => {
    if (!publicKey || !signTransaction) return;
    
    const ctx: Web3RuntimeContext = {
      connection,
      publicKey,
      signTransaction,
    };
    
    // Check if player has access token
    const gate = await executeTokenGate(ctx, 'GameTokenMint...', 100);
    
    if (!gate.hasAccess) {
      alert('Need 100 tokens to claim victory NFT');
      return;
    }
    
    // Mint victory NFT
    const nft = await executeMintNFT(
      ctx,
      'Victory Badge',
      'https://arweave.net/badge.png',
      { timestamp: Date.now().toString() }
    );
    
    alert(`Victory NFT minted: ${nft.mintAddress}`);
  };
  
  return <button onClick={handleGameWin}>Claim Victory</button>;
}

Build docs developers (and LLMs) love