import { Lux, BN, Buffer } from "lux/dist" import { PlatformVMAPI, KeyChain, UTXOSet, UnsignedTx, Tx } from "lux/dist/apis/platformvm" import { PrivateKeyPrefix, DefaultLocalGenesisPrivateKey, UnixNow } 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 pchain: PlatformVMAPI = lux.PChain() const pKeychain: KeyChain = pchain.keyChain() const privKey: string = `${PrivateKeyPrefix}${DefaultLocalGenesisPrivateKey}` pKeychain.importKey(privKey) const pAddressStrings: string[] = pchain.keyChain().getAddressStrings() const threshold: number = 1 const locktime: BN = new BN(0) const memo: Buffer = Buffer.from( "PlatformVM utility method buildAddValidatorTx to add a validator 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(26300000)) const delegationFee: number = 10 const main = async (): Promise => { const stakeAmount: any = await pchain.getMinStake() const platformVMUTXOResponse: any = await pchain.getUTXOs(pAddressStrings) const utxoSet: UTXOSet = platformVMUTXOResponse.utxos const unsignedTx: UnsignedTx = await pchain.buildAddValidatorTx( utxoSet, pAddressStrings, pAddressStrings, pAddressStrings, nodeID, startTime, endTime, stakeAmount.minValidatorStake, pAddressStrings, delegationFee, locktime, threshold, memo, asOf ) const tx: Tx = unsignedTx.sign(pKeychain) const txid: string = await pchain.issueTx(tx) console.log(`Success! TXID: ${txid}`) } main()