import { GetUTXOsResponse } from "ecanna/dist/apis/tknvm/interfaces" import { Ecanna, BN, Buffer } from "ecanna/dist" import { TKNVMAPI, KeyChain, UTXOSet, UnsignedTx, Tx } from "ecanna/dist/apis/tknvm" import { UnixNow } from "ecanna/dist/utils" import { PrivateKeyPrefix, DefaultLocalGenesisPrivateKey } 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 xKeychain: KeyChain = tknchain.keyChain() const privKey: string = `${PrivateKeyPrefix}${DefaultLocalGenesisPrivateKey}` xKeychain.importKey(privKey) const xAddressStrings: string[] = tknchain.keyChain().getAddressStrings() const asOf: BN = UnixNow() const threshold: number = 1 const locktime: BN = new BN(0) const memo: Buffer = Buffer.from( "TKNVM utility method buildBaseTx to send an ANT" ) const main = async (): Promise => { const amount: BN = new BN(5) const tknvmUTXOResponse: GetUTXOsResponse = await tknchain.getUTXOs( xAddressStrings ) const utxoSet: UTXOSet = tknvmUTXOResponse.utxos const assetID: string = "KD4byR998qmVivF2zmrhLb6gjwKGSB5xCerV2nYXb4XNXVGEP" const toAddresses: string[] = [xAddressStrings[0]] const unsignedTx: UnsignedTx = await tknchain.buildBaseTx( utxoSet, amount, assetID, toAddresses, xAddressStrings, xAddressStrings, memo, asOf, locktime, threshold ) const tx: Tx = unsignedTx.sign(xKeychain) const txid: string = await tknchain.issueTx(tx) console.log(`Success! TXID: ${txid}`) } main()