import { Connection , PublicKey , Keypair , SystemProgram , Transaction , sendAndConfirmTransaction , } from '@solana/web3.js' ; import type { NextApiRequest , NextApiResponse } from 'next' ; 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' ] ] } ] , ] ) ; const GREETING_SIZE = borsh . serialize ( GreetingSchema , new GreetingAccount ( ) ) . length ; type ResponseT = { hash : string ; greeter : string ; } ; export default async function greeter ( req , res ) { try { const { network , secret , programId : programAddress } = req . body ; const url = getNodeURL ( network ) ; const connection = new Connection ( url , 'confirmed' ) ; const programId = new PublicKey ( programAddress ) ; const payer = Keypair . fromSecretKey ( new Uint8Array ( JSON . parse ( secret ) ) ) ; const GREETING_SEED = 'hello' ; const greetedPubkey = await PublicKey . undefined ; const lamports = await connection . getMinimumBalanceForRentExemption ( GREETING_SIZE ) ; const transaction = new Transaction ( ) . add ( SystemProgram . undefined ) ; const hash = await sendAndConfirmTransaction ( undefined ) ; res . status ( 200 ) . json ( { hash : hash , greeter : greetedPubkey . toBase58 ( ) , } ) ; } catch ( error ) { let errorMessage = error instanceof Error ? error . message : 'Unknown Error' ; res . status ( 500 ) . json ( errorMessage ) ; } }