import type { NextApiRequest , NextApiResponse } from 'next' ; import { getAvalancheClient } from '@figment-avalanche/lib' ; import { BN } from 'avalanche' ; export default async function ( req , res ) { try { const { secret , network } = req . body ; const client = getAvalancheClient ( network ) ; const amount = '50000000' ; const [ xChain , cChain ] = [ client . XChain ( ) , undefined ] ; const [ xKeychain , cKeychain ] = [ xChain . keyChain ( ) , undefined ] ; const [ xKeypair , cKeypair ] = [ xKeychain . importKey ( secret ) , undefined ] ; const [ xAddress , cAddress ] = [ xKeypair . getAddressString ( ) , undefined ] ; const { utxos } = await xChain . getUTXOs ( xAddress ) ; const chainId = undefined ; const exportTx = await xChain . buildExportTx ( undefined ) ; const hash = await xChain . issueTx ( exportTx . sign ( xKeychain ) ) ; res . status ( 200 ) . json ( hash ) ; } catch ( error ) { let errorMessage = error instanceof Error ? error . message : 'Unknown Error' ; res . status ( 500 ) . json ( errorMessage ) ; } }