Skip to main content

Why Solana?

Solana is ideal for gaming because:
  • Fast: Transactions confirm in ~400ms
  • Cheap: Transaction fees are fractions of a penny
  • Scalable: Handles 50,000+ transactions per second
  • Great Ecosystem: Pump.fun for tokens, Metaplex for NFTs

Wallet Support

G3Engine integrates with popular Solana wallets:
  • Phantom - Most popular Solana wallet
  • Solflare - Feature-rich wallet for power users
  • Backpack - Gaming-focused wallet
  • Any wallet supporting Wallet Adapter
G3Engine uses the official @solana/wallet-adapter library, so any wallet that supports the standard will work.

Network Configuration

Configure which Solana network your game uses:
export type SolanaNetwork = 'devnet' | 'mainnet-beta';

Devnet (Testing)

Use devnet during development:
  • Free test SOL from faucets
  • No real money involved
  • RPC endpoint: https://api.devnet.solana.com

Mainnet-Beta (Production)

Switch to mainnet for your live game:
  • Real SOL and tokens
  • Production-ready
  • RPC endpoint: https://api.mainnet-beta.solana.com
Always thoroughly test on devnet before deploying to mainnet. Real money is at stake on mainnet.

Connecting a Wallet

Players connect their wallet through the in-game Web3 panel:
  1. Click the Web3 icon in your game
  2. Choose their wallet (Phantom, Solflare, etc.)
  3. Approve the connection in their wallet app
  4. Their address and balance appear in-game

Connection State

The connection state is stored in the Web3 store:
interface Web3State {
  // Connection status
  network: SolanaNetwork;          // 'devnet' or 'mainnet-beta'
  rpcEndpoint: string;             // RPC URL for blockchain calls
  walletConnected: boolean;        // Is wallet connected?
  walletAddress: string | null;   // Player's wallet address
  solBalance: number;              // Current SOL balance
}

Checking Connection Status

In your game code:
import { useWeb3Store } from '@/store/web3Store';

function MyGameComponent() {
  const { walletConnected, walletAddress, solBalance } = useWeb3Store();
  
  if (!walletConnected) {
    return <div>Please connect your wallet</div>;
  }
  
  return (
    <div>
      <p>Address: {walletAddress}</p>
      <p>Balance: {solBalance} SOL</p>
    </div>
  );
}

Solana Dependencies

G3Engine includes these Solana libraries:
{
  "@solana/web3.js": "^1.98.4",
  "@solana/spl-token": "^0.4.14",
  "@solana/wallet-adapter-base": "^0.9.27",
  "@solana/wallet-adapter-react": "^0.15.39",
  "@solana/wallet-adapter-react-ui": "^0.9.39",
  "@solana/wallet-adapter-wallets": "^0.19.37",
  "@metaplex-foundation/js": "^0.20.1"
}

Token Operations

G3Engine supports Solana tokens through the SPL Token standard:

Token Info Structure

export interface TokenInfo {
  mint: string;              // Token mint address (unique ID)
  name: string;              // Token name (e.g., "My Game Token")
  symbol: string;            // Token symbol (e.g., "MGT")
  balance: number;           // Player's token balance
  decimals: number;          // Decimal places (usually 9 for Solana)
  imageUri?: string;         // Token logo URL
  
  // Pump.fun specific fields
  isPumpToken?: boolean;           // Launched on Pump.fun?
  bondingCurveComplete?: boolean;  // Graduated to Raydium?
  priceInSol?: number;             // Current price in SOL
}

Viewing Player Tokens

Players can view all their Solana tokens in the Web3 panel:
const { tokens } = useWeb3Store();

tokens.forEach(token => {
  console.log(`${token.name} (${token.symbol}): ${token.balance}`);
});

Pump.fun Integration

G3Engine has built-in support for Pump.fun, the popular Solana token launchpad:

Launching a Token

Use the “Launch Token” Blueprint node or call directly:
import { executeTokenLaunch } from '@/lib/web3Runtime';

const result = await executeTokenLaunch(
  ctx,
  "My Game Token",   // Name
  "MGT",             // Symbol  
  "https://..."      // Image URI
);

console.log(`Token created: ${result.tokenMint}`);
console.log(`Transaction: ${result.txHash}`);

Buying Tokens

Players can buy tokens on the Pump.fun bonding curve:
import { executeBuyToken } from '@/lib/web3Runtime';

const result = await executeBuyToken(
  ctx,
  "TokenMintAddress",  // Which token to buy
  0.1,                 // Amount of SOL to spend
  1                    // Slippage tolerance (1%)
);

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

Selling Tokens

import { executeSellToken } from '@/lib/web3Runtime';

const result = await executeSellToken(
  ctx,
  "TokenMintAddress",  // Which token to sell
  1000000,             // Number of tokens to sell
  1                    // Slippage tolerance (1%)
);

console.log(`Received: ${result.solReceived} SOL`);
Pump.fun tokens use a bonding curve pricing model. Price increases as more people buy, and decreases as people sell.

Checking Balances

Check SOL or token balances:
import { executeCheckBalance } from '@/lib/web3Runtime';

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

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

Sending SOL

Send SOL to another wallet (e.g., for tips or payments):
import { executeSendSOL } from '@/lib/web3Runtime';

const result = await executeSendSOL(
  ctx,
  "RecipientWalletAddress",  // Who receives the SOL
  0.1                        // Amount in SOL
);

console.log(`Transaction: ${result.txHash}`);

Web3 Runtime Context

All Web3 operations use a runtime context that provides blockchain connection:
export interface Web3RuntimeContext {
  connection: Connection;              // Solana RPC connection
  publicKey: PublicKey;                // Player's wallet address
  signTransaction: (tx: Transaction) => Promise<Transaction>;
  signAllTransactions?: (txs: Transaction[]) => Promise<Transaction[]>;
}
This context is automatically created when a player connects their wallet.

Transaction Tracking

All blockchain transactions are tracked in the Web3 store:
export interface Web3Transaction {
  id: string;                    // Unique transaction ID
  type: 'token_launch' | 'buy' | 'sell' | 'mint_nft' | 'transfer' | 'airdrop';
  signature: string;             // Blockchain transaction hash
  status: 'pending' | 'confirmed' | 'failed';
  description: string;           // Human-readable description
  timestamp: number;             // When transaction was created
}
View transaction history:
const { transactions } = useWeb3Store();

transactions.forEach(tx => {
  console.log(`${tx.type}: ${tx.status} - ${tx.description}`);
});

Custom RPC Endpoints

For better performance, use a custom RPC provider:
const { setRpcEndpoint } = useWeb3Store();

// Use your own RPC endpoint
setRpcEndpoint('https://your-rpc-provider.com');
Popular RPC providers:
  • Helius - Fast, reliable, generous free tier
  • QuickNode - Enterprise-grade infrastructure
  • Alchemy - Developer-friendly with great tools
Public RPC endpoints (api.mainnet-beta.solana.com) can be slow or rate-limited. Use a dedicated RPC provider for production games.

Next Steps

Token Management

Learn how to manage game tokens

NFT Support

Mint and use NFTs in your game

Build docs developers (and LLMs) love