import { Ecanna, BinTools, BN, Buffer } from "ecanna/dist" import { StakeVMAPI, KeyChain as StakeVMKeyChain } from "ecanna/dist/apis/stakevm" import { EVMAPI, KeyChain as EVMKeyChain, UnsignedTx, Tx, EVMInput, ExportTx, SECPTransferOutput, TransferableOutput } from "ecanna/dist/apis/evm" import { PrivateKeyPrefix, DefaultLocalGenesisPrivateKey, Defaults, ONEECNA } from "ecanna/dist/utils" const Web3 = require("web3") 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 evmchain: EVMAPI = ecanna.EVMChain() const bintools: BinTools = BinTools.getInstance() const pKeychain: StakeVMKeyChain = stkchain.keyChain() let privKey: string = `${PrivateKeyPrefix}${DefaultLocalGenesisPrivateKey}` // TKN-custom18jma8ppw3nhx5r4ap8clazz0dps7rv5u9xde7p // let privKey: string = "PrivateKey-2PvNEohp3sNL41g4XcCBym5hpeT1szSTZXxL7VGS28eoGvq3k7" const cKeychain: EVMKeyChain = evmchain.keyChain() cKeychain.importKey(privKey) privKey = "PrivateKey-24gdABgapjnsJfnYkfev6YPyQhTaCU72T9bavtDNTYivBLp2eW" // STK-custom1u6eth2fg33ye63mnyu5jswtj326jaypvhyar45 pKeychain.importKey(privKey) // privKey = "PrivateKey-R6e8f5QSa89DjpvL9asNdhdJ4u8VqzMJStPV8VVdDmLgPd8a4" // TKN-custom15s7p7mkdev0uajrd0pzxh88kr8ryccztnlmzvj privKey = "PrivateKey-rKsiN3X4NSJcPpWxMSh7WcuY653NGQ7tfADgQwDZ9yyUPPDG9" // STK-custom1jwwk62ktygl0w29rsq2hq55amamhpvx82kfnte pKeychain.importKey(privKey) const pAddresses: Buffer[] = stkchain.keyChain().getAddresses() const cAddresses: Buffer[] = evmchain.keyChain().getAddresses() const stkChainId: string = Defaults.network[networkID].STK.blockchainID const stkChainIdBuf: Buffer = bintools.cb58Decode(stkChainId) const evmChainId: string = Defaults.network[networkID].EVM.blockchainID const evmChainIdBuf: Buffer = bintools.cb58Decode(evmChainId) const ecnaAssetID: string = Defaults.network[networkID].TKN.ecnaAssetID const ecnaAssetIDBuf: Buffer = bintools.cb58Decode(ecnaAssetID) const cHexAddress: string = "0xeA6B543A9E625C04745EcA3D7a74D74B733b8C15" const evmInputs: EVMInput[] = [] const exportedOuts: TransferableOutput[] = [] const path: string = "/ext/bc/STK/rpc" const web3 = new Web3(`${protocol}://${ip}:${port}${path}`) const threshold: number = 2 const main = async (): Promise => { let balance: BN = await web3.eth.getBalance(cHexAddress) balance = new BN(balance.toString().substring(0, 17)) const fee: BN = evmchain.getDefaultTxFee() const txcount = await web3.eth.getTransactionCount(cHexAddress) const nonce: number = txcount const locktime: BN = new BN(0) const evmInput: EVMInput = new EVMInput( cHexAddress, ONEECNA, ecnaAssetID, nonce ) evmInput.addSignatureIdx(0, cAddresses[0]) evmInputs.push(evmInput) const secpTransferOutput: SECPTransferOutput = new SECPTransferOutput( ONEECNA.sub(fee.mul(new BN(2))), pAddresses, locktime, threshold ) const transferableOutput: TransferableOutput = new TransferableOutput( ecnaAssetIDBuf, secpTransferOutput ) exportedOuts.push(transferableOutput) const exportTx: ExportTx = new ExportTx( networkID, evmChainIdBuf, stkChainIdBuf, evmInputs, exportedOuts ) const unsignedTx: UnsignedTx = new UnsignedTx(exportTx) const tx: Tx = unsignedTx.sign(cKeychain) const txid: string = await evmchain.issueTx(tx) console.log(`Success! TXID: ${txid}`) } main()