InitiaClient.ts 841 B

1234567891011121314151617181920212223242526272829303132
  1. import { InitiaTask } from './InitiaTask'
  2. import { MsgSend } from '@initia/initia.js'
  3. export class InitiaClient extends InitiaTask {
  4. constructor(mnemonic: string, useProxy: boolean = false) {
  5. super(mnemonic, useProxy)
  6. }
  7. async transfer(to: string, amount: number) {
  8. const msg = new MsgSend(
  9. this.wallet.key.accAddress,
  10. to,
  11. `${amount * Math.pow(10, 6)}uinit`,
  12. )
  13. const signed = await this.wallet.createAndSignTx({
  14. // sequence: 3,
  15. msgs: [msg],
  16. })
  17. const broadcast = await this.lcd.tx.broadcast(signed)
  18. return broadcast.txhash
  19. }
  20. async week2Task2(toAddr: string) {
  21. const uinitAmount = await this.getTargetAmount(toAddr)
  22. console.log(uinitAmount)
  23. if (Number(uinitAmount) > 0) {
  24. return `done`
  25. } else {
  26. return await this.transfer(toAddr, 1)
  27. }
  28. }
  29. }