InitiaClient.ts 804 B

12345678910111213141516171819202122232425262728293031
  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.getInitAmount()
  22. if (Number(uinitAmount) > 0) {
  23. return `done`
  24. } else {
  25. return await this.transfer(toAddr, 1)
  26. }
  27. }
  28. }