import { Avalanche, BN, Buffer } from "avalanche/dist" import { AVMAPI, KeyChain as AVMKeyChain, UTXOSet, UnsignedTx, Tx } from "avalanche/dist/apis/avm" import { GetUTXOsResponse } from "avalanche/dist/apis/avm/interfaces" import { KeyChain as EVMKeyChain, EVMAPI } from "avalanche/dist/apis/evm" import { PrivateKeyPrefix, DefaultLocalGenesisPrivateKey, Defaults, UnixNow } from "avalanche/dist/utils" const ip: string = "localhost" const port: number = 9650 const protocol: string = "http" const networkID: number = 1337 const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const cchain: EVMAPI = avalanche.CChain() const xKeychain: AVMKeyChain = xchain.keyChain() const cKeychain: EVMKeyChain = cchain.keyChain() const privKey: string = `${PrivateKeyPrefix}${DefaultLocalGenesisPrivateKey}` xKeychain.importKey(privKey) cKeychain.importKey(privKey) const xAddressStrings: string[] = xchain.keyChain().getAddressStrings() const cAddressStrings: string[] = cchain.keyChain().getAddressStrings() const cChainBlockchainID: string = Defaults.network[networkID].C.blockchainID const locktime: BN = new BN(0) const asOf: BN = UnixNow() const memo: Buffer = Buffer.from( "AVM utility method buildExportTx to export ANT to the C-Chain from the X-Chain" ) const main = async (): Promise => { const avmUTXOResponse: GetUTXOsResponse = await xchain.getUTXOs( xAddressStrings ) const utxoSet: UTXOSet = avmUTXOResponse.utxos const amount: BN = new BN(350) const threshold: number = 1 const assetID: string = "Ycg5QzddNwe3ebfFXhoGUDnWgC6GE88QRakRnn9dp3nGwqCwD" const unsignedTx: UnsignedTx = await xchain.buildExportTx( utxoSet, amount, cChainBlockchainID, cAddressStrings, xAddressStrings, xAddressStrings, memo, asOf, locktime, threshold, assetID ) const tx: Tx = unsignedTx.sign(xKeychain) const txid: string = await xchain.issueTx(tx) console.log(`Success! TXID: ${txid}`) } main()