import { Lux, BN } from "lux/dist" import { XVMAPI, KeyChain as XVMKeyChain } from "lux/dist/apis/xvm" import { EVMAPI, KeyChain as EVMKeyChain, UnsignedTx, Tx, UTXOSet } from "lux/dist/apis/evm" import { PrivateKeyPrefix, DefaultLocalGenesisPrivateKey, Defaults, costImportTx } from "lux/dist/utils" const ip: string = "localhost" const port: number = 9650 const protocol: string = "http" const networkID: number = 1337 const lux: Lux = new Lux(ip, port, protocol, networkID) const xchain: XVMAPI = lux.XChain() const cchain: EVMAPI = lux.CChain() const xKeychain: XVMKeyChain = xchain.keyChain() const cHexAddress: string = "0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC" const privKey: string = `${PrivateKeyPrefix}${DefaultLocalGenesisPrivateKey}` const cKeychain: EVMKeyChain = cchain.keyChain() xKeychain.importKey(privKey) cKeychain.importKey(privKey) const cAddressStrings: string[] = cchain.keyChain().getAddressStrings() const xChainBlockchainId: string = Defaults.network[networkID].X.blockchainID const main = async (): Promise => { const baseFeeResponse: string = await cchain.getBaseFee() const baseFee = new BN(parseInt(baseFeeResponse, 16) / 1e9) let fee: BN = baseFee const evmUTXOResponse: any = await cchain.getUTXOs( cAddressStrings, xChainBlockchainId ) const utxoSet: UTXOSet = evmUTXOResponse.utxos let unsignedTx: UnsignedTx = await cchain.buildImportTx( utxoSet, cHexAddress, cAddressStrings, xChainBlockchainId, cAddressStrings, fee ) const importCost: number = costImportTx(unsignedTx) fee = baseFee.mul(new BN(importCost)) unsignedTx = await cchain.buildImportTx( utxoSet, cHexAddress, cAddressStrings, xChainBlockchainId, cAddressStrings, fee ) const tx: Tx = unsignedTx.sign(cKeychain) const txid: string = await cchain.issueTx(tx) console.log(`Success! TXID: ${txid}`) } main()