Skip to main content

Quick summary

Gx402 provides x402 integration examples and server middleware so teams can accept in-app payments (miniapps) and in-game purchases from engine builds (Unity/Unreal) running inside Farcaster or as standalone games. We are not shipping a proprietary SDK — instead, you get:
  • Engine-native examples
  • A recommended Express middleware pattern
  • Deployment notes for reliable x402 payments (create → sign → confirm → finalize)
(Adapted from the x402 miniapp template)

Prerequisites

  • Node.js 18+ and a package manager (pnpm, npm, or yarn)
  • Farcaster uses it’s In-App wallet connection so you don’t need any external wallet to connect
  • x402 provider account & API keys (from your x402 provider)
  • Unity (2021+) or Unreal (4.27+/5.x) for engine builds intended to run inside Farcaster or as standalone apps
  • Basic knowledge of wallet signing (EIP-191 or EIP-712) and server-side HMAC/secret handling

We are still working on the flow of Unity Integrations for Miniapp, We will be providing the Unity WebGL Integration Kit soon

Farcaster Miniapp Integration Flow

  • Farcaster Miniapps provide native in-app wallet connections (e.g., Wagmi, Privy, or custom connectors).
  • The Unity WebGL build runs seamlessly inside the Farcaster frame, maintaining wallet context and session continuity.
  • All in-game and external transactions follow the same x402-compliant payment logic, powered by the Gx402 middleware.
  • Gx402 acts as a facilitator layer, verifying Solana transactions and unlocking protected APIs or in-game assets post-payment.
  • This architecture ensures cross-platform compatibility, allowing the same Unity game to run on Farcaster, Telegram, or browser-based miniapps with minimal code changes.

Server

export async function POST(req: NextRequest) {
 try {
   const paymentHeader = x402.extractPayment(req.headers);

   const paymentRequirements = await x402.createPaymentRequirements({
     price: {
       amount: "2500000",
       asset: {
         address: "Your address",
         decimals: 6,
       },
     },
     network: 'solana-devnet' || 'base-sepolia'
     config: {
       description: 'Response from Gx402',
       resource: `${process.env.NEXT_PUBLIC_BASE_URL || 'http://localhost:61664'}/api/-your-endpoint` as `${string}://${string}`,
     },
   });

   if (!paymentHeader) {
     const response = x402.create402Response(paymentRequirements);
     return NextResponse.json(response.body, {
       status: response.status,
     });
   }

   const verified = await x402.verifyPayment(paymentHeader, paymentRequirements);
   if (!verified) {
     return NextResponse.json(
       { error: 'Invalid or unverified payment' },
       { status: 402, headers: corsHeaders }
     );
   }

   const body = await req.json().catch(() => ({}));
   const result = {
     message: '✅ Hello, you paid successfully!',
     receivedData: body,
   };

   await x402.settlePayment(paymentHeader, paymentRequirements);

   return NextResponse.json(result, { headers: corsHeaders });

 } catch (error: any) {
   console.error('API Error:', error);
   return NextResponse.json(
     { error: 'Internal server error' },
     { status: 500, headers: corsHeaders }
   );
 }
}


---

Unity Implementation

For now we will be using the same approach for build as of Unity Integration section
We will be providing the code snippet to connect the In-App wallet inside the game as repo is still under construction

Folder Structure (For Unity WebGL build)

farcaster-miniapp/
├── app/
   ├── .well-known/
   └── farcaster.json
   ├── api/
   ├── notify/
   ├── protected/
   └── webhook/
   ├── globals.css
   ├── layout.tsx
   ├── page.tsx
   ├── providers.tsx
   ├── theme.css
   └── unityplayer.tsx

├── lib/

├── node_modules/

├── public/
   └── unity/
       ├── Build/
   ├── Build.data
   ├── Build.framework.js
   ├── Build.loader.js
   ├── Build.wasm
       └── TemplateData/
           └── index.html

└── package.json