import type { NextApiRequest , NextApiResponse } from 'next' ; import { Connection , PublicKey } from '@solana/web3.js' ; import { getNodeURL } from '@figment-solana/lib' ; import * as borsh from 'borsh' ; class GreetingAccount { counter = 0 ; constructor ( fields = undefined ) { if ( fields ) { this . counter = fields . counter ; } } } const GreetingSchema = new Map ( [ [ GreetingAccount , { kind : 'struct' , fields : [ [ 'counter' , 'u32' ] ] } ] , ] ) ; export default async function getter ( req , res ) { try { const { network , greeter } = req . body ; const url = getNodeURL ( network ) ; const connection = new Connection ( url , 'confirmed' ) ; const greeterPublicKey = new PublicKey ( greeter ) ; const accountInfo = await connection . getAccountInfo ( greeterPublicKey ) ; if ( accountInfo === null ) { throw new Error ( 'Error: cannot find the greeted account' ) ; } const greeting = borsh . deserialize ( undefined ) ; console . log ( greeting ) ; res . status ( 200 ) . json ( undefined ) ; } catch ( error ) { let errorMessage = error instanceof Error ? error . message : 'Unknown Error' ; console . log ( errorMessage ) ; res . status ( 500 ) . json ( errorMessage ) ; } }