hel 1 anno fa
parent
commit
c5c8f72868
2 ha cambiato i file con 14 aggiunte e 9 eliminazioni
  1. 11 3
      src/initiaClient.ts
  2. 3 6
      src/swapTester.ts

+ 11 - 3
src/initiaClient.ts

@@ -5,8 +5,9 @@ import {
   MsgExecute,
   Wallet,
 } from '@initia/initia.js'
+import { validatorArray } from './validatorArray'
 
-class InitiaClient {
+export class InitiaClient {
   key: MnemonicKey
   lcd: LCDClient
   wallet: Wallet
@@ -52,10 +53,17 @@ class InitiaClient {
   }
 
   async stakeInit() {
+    const randomValidator =
+      validatorArray[Math.floor(Math.random() * validatorArray.length)]
     const msg = new MsgDelegate(
-      'init1kdwzpz3wzvpdj90gtga4fw5zm9tk4cyrgnjauu', // delegator address
-      'init18sj3x80fdjc6gzfvwl7lf8sxcvuvqjpvcmp6np', // validator's operator addres
+      'init1w6ftxlsv7y5putq955ymxh2kd0wru7nqshetka', // delegator address
+      randomValidator, // validator's operator addres
       '100000uinit', // delegate amount
     )
+    const signed = await this.wallet.createAndSignTx({
+      msgs: [msg],
+    })
+    const broadcast = await this.lcd.tx.broadcast(signed)
+    console.log(broadcast)
   }
 }

+ 3 - 6
src/swapTester.ts

@@ -1,4 +1,5 @@
 import { LCDClient, MnemonicKey, MsgExecute, Wallet } from '@initia/initia.js'
+import { InitiaClient } from './initiaClient'
 
 const key = new MnemonicKey({
   mnemonic:
@@ -29,11 +30,7 @@ const msg = new MsgExecute(
 )
 
 async function main() {
-  const signed = await wallet.createAndSignTx({
-    msgs: [msg],
-    memo: '',
-  })
-  const broadcast = await lcd.tx.broadcast(signed)
-  console.log(broadcast)
+  const client = new InitiaClient(key.mnemonic)
+  await client.stakeInit()
 }
 main()