import { Dcomm, BN, Buffer } from "dcomm/dist" import { DVMAPI, KeyChain as DVMKeyChain, UTXOSet, UnsignedTx, Tx } from "dcomm/dist/apis/dvm" import { GetUTXOsResponse } from "dcomm/dist/apis/dvm/interfaces" import { KeyChain as EVMKeyChain, EVMAPI } from "dcomm/dist/apis/evm" import { PrivateKeyPrefix, DefaultLocalGenesisPrivateKey, Defaults, UnixNow } from "dcomm/dist/utils" const ip: string = "localhost" const port: number = 9650 const protocol: string = "http" const networkID: number = 1337 const dcomm: Dcomm = new Dcomm(ip, port, protocol, networkID) const astchain: DVMAPI = dcomm.ASTChain() const actchain: EVMAPI = dcomm.ACTChain() const xKeychain: DVMKeyChain = astchain.keyChain() const cKeychain: EVMKeyChain = actchain.keyChain() const privKey: string = `${PrivateKeyPrefix}${DefaultLocalGenesisPrivateKey}` xKeychain.importKey(privKey) cKeychain.importKey(privKey) const xAddressStrings: string[] = astchain.keyChain().getAddressStrings() const cAddressStrings: string[] = actchain.keyChain().getAddressStrings() const actChainBlockchainID: string = Defaults.network[networkID].ACT.blockchainID const locktime: BN = new BN(0) const asOf: BN = UnixNow() const memo: Buffer = Buffer.from( "DVM utility method buildExportTx to export ANT to the ACT-Chain from the AST-Chain" ) const main = async (): Promise => { const dvmUTXOResponse: GetUTXOsResponse = await astchain.getUTXOs( xAddressStrings ) const utxoSet: UTXOSet = dvmUTXOResponse.utxos const amount: BN = new BN(350) const threshold: number = 1 const assetID: string = "Ycg5QzddNwe3ebfFXhoGUDnWgC6GE88QRakRnn9dp3nGwqCwD" const unsignedTx: UnsignedTx = await astchain.buildExportTx( utxoSet, amount, actChainBlockchainID, cAddressStrings, xAddressStrings, xAddressStrings, memo, asOf, locktime, threshold, assetID ) const tx: Tx = unsignedTx.sign(xKeychain) const txid: string = await astchain.issueTx(tx) console.log(`Success! TXID: ${txid}`) } main()