import { Ecanna, BN, Buffer } from "ecanna/dist" import { TKNVMAPI, KeyChain as TKNVMKeyChain, UTXOSet, UnsignedTx, Tx } from "ecanna/dist/apis/tknvm" import { GetUTXOsResponse } from "ecanna/dist/apis/tknvm/interfaces" import { KeyChain as EVMKeyChain, EVMAPI } from "ecanna/dist/apis/evm" import { PrivateKeyPrefix, DefaultLocalGenesisPrivateKey, Defaults, UnixNow } from "ecanna/dist/utils" const ip: string = "localhost" const port: number = 9650 const protocol: string = "http" const networkID: number = 1337 const ecanna: Ecanna = new Ecanna(ip, port, protocol, networkID) const tknchain: TKNVMAPI = ecanna.TKNChain() const evmchain: EVMAPI = ecanna.EVMChain() const xKeychain: TKNVMKeyChain = tknchain.keyChain() const cKeychain: EVMKeyChain = evmchain.keyChain() const privKey: string = `${PrivateKeyPrefix}${DefaultLocalGenesisPrivateKey}` xKeychain.importKey(privKey) cKeychain.importKey(privKey) const xAddressStrings: string[] = tknchain.keyChain().getAddressStrings() const cAddressStrings: string[] = evmchain.keyChain().getAddressStrings() const evmChainBlockchainID: string = Defaults.network[networkID].EVM.blockchainID const locktime: BN = new BN(0) const asOf: BN = UnixNow() const memo: Buffer = Buffer.from( "TKNVM utility method buildExportTx to export ANT to the EVM-Chain from the TKN-Chain" ) const main = async (): Promise => { const tknvmUTXOResponse: GetUTXOsResponse = await tknchain.getUTXOs( xAddressStrings ) const utxoSet: UTXOSet = tknvmUTXOResponse.utxos const amount: BN = new BN(350) const threshold: number = 1 const assetID: string = "Ycg5QzddNwe3ebfFXhoGUDnWgC6GE88QRakRnn9dp3nGwqCwD" const unsignedTx: UnsignedTx = await tknchain.buildExportTx( utxoSet, amount, evmChainBlockchainID, cAddressStrings, xAddressStrings, xAddressStrings, memo, asOf, locktime, threshold, assetID ) const tx: Tx = unsignedTx.sign(xKeychain) const txid: string = await tknchain.issueTx(tx) console.log(`Success! TXID: ${txid}`) } main()