import { Lux, BinTools, BN, Buffer, GenesisData } from "lux/dist" import { PlatformVMAPI, KeyChain, UTXOSet, UnsignedTx, Tx } from "lux/dist/apis/platformvm" import { PrivateKeyPrefix, DefaultLocalGenesisPrivateKey, UnixNow } from "lux/dist/utils" /** * @ignore */ const bintools: BinTools = BinTools.getInstance() 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() // Keychain with 4 keys-A, B, C, and D const pKeychain: KeyChain = pchain.keyChain() // Keypair A let privKey: string = `${PrivateKeyPrefix}${DefaultLocalGenesisPrivateKey}` // P-custom18jma8ppw3nhx5r4ap8clazz0dps7rv5u9xde7p pKeychain.importKey(privKey) // Keypair B privKey = "PrivateKey-R6e8f5QSa89DjpvL9asNdhdJ4u8VqzMJStPV8VVdDmLgPd8a4" // P-custom15s7p7mkdev0uajrd0pzxh88kr8ryccztnlmzvj pKeychain.importKey(privKey) // Keypair C privKey = "PrivateKey-24gdABgapjnsJfnYkfev6YPyQhTaCU72T9bavtDNTYivBLp2eW" // P-custom1u6eth2fg33ye63mnyu5jswtj326jaypvhyar45 pKeychain.importKey(privKey) // Keypair D privKey = "PrivateKey-2uWuEQbY5t7NPzgqzDrXSgGPhi3uyKj2FeAvPUHYo6CmENHJfn" // P-custom1t3qjau2pf3ys83yallqt4y5xc3l6ya5f7wr6aq pKeychain.importKey(privKey) const pAddressStrings: string[] = pchain.keyChain().getAddressStrings() const pAddresses: Buffer[] = pchain.keyChain().getAddresses() const asOf: BN = UnixNow() const main = async (): Promise => { const platformVMUTXOResponse: any = await pchain.getUTXOs(pAddressStrings) const utxoSet: UTXOSet = platformVMUTXOResponse.utxos const genesisDataStr: string = "11111DdZMhYXUZiFV9FNpfpTSQroysjHyMuT5zapYkPYrmap7t7S3sDNNwFzngxR9x1XmoRj5JK1XomX8RHvXYY5h3qYeEsMQRF8Ypia7p1CFHDo6KGSjMdiQkrmpvL8AvoezSxVWKXt2ubmBCnSkpPjnQbBSF7gNg4sPu1PXdh1eKgthaSFREqqG5FKMrWNiS6U87kxCmbKjkmBvwnAd6TpNx75YEiS9YKMyHaBZjkRDNf6Nj1" const subnetIDStr: string = "2cXEvbdDaP6q6srB6x1T14raebpJaM4s2t9NE5kiXzLqLXQDWm" const memo: Buffer = Buffer.from( "Utility function to create a CreateChainTx transaction" ) const subnetID: Buffer = bintools.cb58Decode(subnetIDStr) const chainName: string = "EPIC XVM" const vmID: string = "xvm" const fxIDs: string[] = ["secp256k1fx", "nftfx", "propertyfx"] // Only for XVM serialization. For other VMs comment these 2 lines const genesisData: GenesisData = new GenesisData() genesisData.fromBuffer(bintools.cb58Decode(genesisDataStr)) // For VMs other than XVM. For XVM comment this line // const genesisData = genesisDataStr const subnetAuthCredentials: [number, Buffer][] = [ [0, pAddresses[3]], [1, pAddresses[1]] ] const unsignedTx: UnsignedTx = await pchain.buildCreateChainTx( utxoSet, pAddressStrings, pAddressStrings, subnetID, chainName, vmID, fxIDs, genesisData, memo, asOf, subnetAuthCredentials ) const tx: Tx = unsignedTx.sign(pKeychain) const txid: string = await pchain.issueTx(tx) console.log(`Success! TXID: ${txid}`) } main()