PHP WebShell
Текущая директория: /usr/lib/node_modules/bitgo/node_modules/avalanche/examples/platformvm
Просмотр файла: buildCreateSubnetTx.ts
import { Avalanche, BN, Buffer } from "avalanche/dist"
import {
PlatformVMAPI,
KeyChain,
UTXOSet,
UnsignedTx,
Tx
} from "avalanche/dist/apis/platformvm"
import { GetUTXOsResponse } from "avalanche/dist/apis/platformvm/interfaces"
import {
PrivateKeyPrefix,
DefaultLocalGenesisPrivateKey,
UnixNow
} from "avalanche/dist/utils"
const ip: string = "localhost"
const port: number = 9650
const protocol: string = "http"
const networkID: number = 1337
const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID)
const pchain: PlatformVMAPI = avalanche.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 threshold: number = 2
const memo: Buffer = Buffer.from(
"PlatformVM utility method buildCreateSubnetTx to create a CreateSubnetTx which creates a 1-of-2 AVAX utxo and a 2-of-3 SubnetAuth"
)
const asOf: BN = UnixNow()
const subnetAuthKeychain: string[] = [
pAddressStrings[1],
pAddressStrings[2],
pAddressStrings[3]
]
const main = async (): Promise<any> => {
const platformVMUTXOResponse: GetUTXOsResponse = await pchain.getUTXOs(
pAddressStrings
)
const utxoSet: UTXOSet = platformVMUTXOResponse.utxos
const unsignedTx: UnsignedTx = await pchain.buildCreateSubnetTx(
utxoSet,
pAddressStrings,
pAddressStrings,
subnetAuthKeychain,
threshold,
memo,
asOf
)
const tx: Tx = unsignedTx.sign(pKeychain)
const txid: string = await pchain.issueTx(tx)
console.log(`Success! TXID: ${txid}`)
}
main()
Выполнить команду
Для локальной разработки. Не используйте в интернете!