I'm currently trying to fetch-transactions in a serverless function using vercel and getting this error:
Error in GET /fetch-transactions: TypeError: s.Wallet is not a constructor
Is there a special way to connect when doing so from a server?
Here is my code:
export const runtime = 'nodejs'; export const dynamic = 'force-dynamic'; import { NextResponse } from 'next/server'; import { getPrismaClient } from '../utils/prisma'; import * as anchor from '@coral-xyz/anchor'; export async function GET(request) { const prisma = getPrismaClient(); const { searchParams } = new URL(request.url); const address = searchParams.get('address'); if (!address) { return NextResponse.json({ error: 'Address is required' }, { status: 400 }); } try { const rpcEndpoint = process.env.NEXT_PUBLIC_RPC_ENDPOINT; const serverKeypairBase64 = process.env.SERVER_KEYPAIR_BASE64; if (!rpcEndpoint) { throw new Error('RPC endpoint is not defined in NEXT_PUBLIC_RPC_ENDPOINT'); } if (!serverKeypairBase64) { throw new Error('Server keypair is not defined in SERVER_KEYPAIR_BASE64'); } const serverKeypairUint8Array = Uint8Array.from( JSON.parse(Buffer.from(serverKeypairBase64, 'base64').toString()) ); console.log('DEBUG CHECK 1'); const serverKeypair = anchor.web3.Keypair.fromSecretKey(serverKeypairUint8Array); console.log('DEBUG CHECK 2'); const wallet = new anchor.Wallet(serverKeypair); console.log('DEBUG CHECK 3'); const connection = new anchor.web3.Connection(rpcEndpoint, 'confirmed'); console.log('DEBUG CHECK 4'); const provider = new anchor.AnchorProvider(connection, wallet, {}); anchor.setProvider(provider); const programId = new anchor.web3.PublicKey('PROGRAM_ID'); const idl = await anchor.Program.fetchIdl(programId, provider); const program = new anchor.Program(idl, programId, provider);
The server logs:
DEBUG CHECK 1DEBUG CHECK 2
and then the error
Thanks for your help!