import { Lux, BN, Buffer } from "lux/dist" import { PlatformVMAPI, KeyChain, UTXOSet, UnsignedTx, Tx } from "lux/dist/apis/platformvm" import { PrivateKeyPrefix, DefaultLocalGenesisPrivateKey, Defaults, 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 cChainBlockchainID: string = Defaults.network[networkID].C.blockchainID const pChainBlockchainID: string = Defaults.network[networkID].P.blockchainID const threshold: number = 1 const locktime: BN = new BN(0) const memo: Buffer = Buffer.from( "PlatformVM utility method buildImportTx to import LUX to the P-Chain from the X-Chain" ) const asOf: BN = UnixNow() const main = async (): Promise => { const platformVMUTXOResponse: any = await pchain.getUTXOs( pAddressStrings, cChainBlockchainID ) const utxoSet: UTXOSet = platformVMUTXOResponse.utxos const unsignedTx: UnsignedTx = await pchain.buildImportTx( utxoSet, pAddressStrings, cChainBlockchainID, pAddressStrings, pAddressStrings, pAddressStrings, memo, asOf, locktime, threshold ) const tx: Tx = unsignedTx.sign(pKeychain) const txid: string = await pchain.issueTx(tx) console.log(`Success! TXID: ${txid}`) } main()