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
Token name (e.g., “My Game Token”)
Token symbol (e.g., “GAME”)
IPFS or Arweave URI for token image
The created token’s mint address
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
Token mint address to buy
Slippage tolerance percentage (default: 1%)
Amount of tokens received
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
Token mint address to sell
Slippage tolerance percentage
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`);
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
IPFS or Arweave URI for NFT image
Optional NFT attributes/metadata
The created NFT’s mint address
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
Token mint address to check
Minimum token balance required
Whether the player has sufficient tokens
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
Token mint address to check. If omitted or ‘SOL’, returns SOL balance
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
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
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 NFT → executeMintNFT
🔐 Token Gate → executeTokenGate
💎 Check Balance → executeCheckBalance
⬡ Send SOL → executeSendSOL
📊 Get Token Price → executeGetTokenPrice
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>;
}