import { Ecanna, BN, Buffer } from "ecanna/dist" import { StakeVMAPI, KeyChain, UTXOSet, UnsignedTx, Tx } from "ecanna/dist/apis/stakevm" import { PrivateKeyPrefix, DefaultLocalGenesisPrivateKey, 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 threshold: number = 1 const locktime: BN = new BN(0) const memo: Buffer = Buffer.from( "StakeVM utility method buildAddDelegatorTx to add a delegator to the primary subnet" ) const asOf: BN = UnixNow() const nodeID: string = "NodeID-DueWyGi3B9jtKfa9mPoecd4YSDJ1ftF69" const startTime: BN = UnixNow().add(new BN(60 * 1)) const endTime: BN = startTime.add(new BN(2630000)) const main = async (): Promise => { const stakeAmount: any = await stkchain.getMinStake() const stakeVMUTXOResponse: any = await stkchain.getUTXOs(pAddressStrings) const utxoSet: UTXOSet = stakeVMUTXOResponse.utxos const unsignedTx: UnsignedTx = await stkchain.buildAddDelegatorTx( utxoSet, pAddressStrings, pAddressStrings, pAddressStrings, nodeID, startTime, endTime, stakeAmount.minDelegatorStake, pAddressStrings, locktime, threshold, memo, asOf ) const tx: Tx = unsignedTx.sign(pKeychain) const txid: string = await stkchain.issueTx(tx) console.log(`Success! TXID: ${txid}`) } main()