PHP WebShell
Текущая директория: /usr/lib/node_modules/bitgo/node_modules/avalanche/examples/platformvm
Просмотр файла: buildAddDelegatorTx.ts
import { Avalanche, BN, Buffer } from "avalanche/dist"
import {
PlatformVMAPI,
KeyChain,
UTXOSet,
UnsignedTx,
Tx
} from "avalanche/dist/apis/platformvm"
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()
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 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<any> => {
const stakeAmount: any = await pchain.getMinStake()
const platformVMUTXOResponse: any = await pchain.getUTXOs(pAddressStrings)
const utxoSet: UTXOSet = platformVMUTXOResponse.utxos
const unsignedTx: UnsignedTx = await pchain.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 pchain.issueTx(tx)
console.log(`Success! TXID: ${txid}`)
}
main()
Выполнить команду
Для локальной разработки. Не используйте в интернете!