import { Ecanna, BN, Buffer } from "ecanna/dist" import { StakeVMAPI, KeyChain, UTXOSet, UnsignedTx, Tx } from "ecanna/dist/apis/stakevm" 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 stkchain: StakeVMAPI = ecanna.STKChain() const pKeychain: KeyChain = stkchain.keyChain() const privKey: string = `${PrivateKeyPrefix}${DefaultLocalGenesisPrivateKey}` pKeychain.importKey(privKey) const pAddressStrings: string[] = stkchain.keyChain().getAddressStrings() const evmChainBlockchainID: string = Defaults.network[networkID].EVM.blockchainID const stkChainBlockchainID: string = Defaults.network[networkID].STK.blockchainID const threshold: number = 1 const locktime: BN = new BN(0) const memo: Buffer = Buffer.from( "StakeVM utility method buildImportTx to import ECNA to the STK-Chain from the TKN-Chain" ) const asOf: BN = UnixNow() const main = async (): Promise => { const stakeVMUTXOResponse: any = await stkchain.getUTXOs( pAddressStrings, evmChainBlockchainID ) const utxoSet: UTXOSet = stakeVMUTXOResponse.utxos const unsignedTx: UnsignedTx = await stkchain.buildImportTx( utxoSet, pAddressStrings, evmChainBlockchainID, pAddressStrings, pAddressStrings, pAddressStrings, memo, asOf, locktime, threshold ) const tx: Tx = unsignedTx.sign(pKeychain) const txid: string = await stkchain.issueTx(tx) console.log(`Success! TXID: ${txid}`) } main()