|
@@ -0,0 +1,61 @@
|
|
|
+import {
|
|
|
+ LCDClient,
|
|
|
+ MnemonicKey,
|
|
|
+ MsgDelegate,
|
|
|
+ MsgExecute,
|
|
|
+ Wallet,
|
|
|
+} from '@initia/initia.js'
|
|
|
+
|
|
|
+class InitiaClient {
|
|
|
+ key: MnemonicKey
|
|
|
+ lcd: LCDClient
|
|
|
+ wallet: Wallet
|
|
|
+ constructor(mnemonic: string) {
|
|
|
+ this.key = new MnemonicKey({
|
|
|
+ mnemonic: mnemonic,
|
|
|
+ })
|
|
|
+
|
|
|
+ this.lcd = new LCDClient('https://api-initia-testnet.whispernode.com/', {
|
|
|
+ chainId: 'initiation-1',
|
|
|
+ })
|
|
|
+
|
|
|
+ this.wallet = new Wallet(this.lcd, this.key)
|
|
|
+ }
|
|
|
+
|
|
|
+ async checkBalance() {
|
|
|
+ const balances = await this.lcd.bank.balance(
|
|
|
+ 'init14l3c2vxrdvu6y0sqykppey930s4kufsvt97aeu',
|
|
|
+ )
|
|
|
+ console.log(balances)
|
|
|
+ //todo filter balance
|
|
|
+ }
|
|
|
+
|
|
|
+ async swapScript() {
|
|
|
+ const msg = new MsgExecute(
|
|
|
+ this.key.accAddress,
|
|
|
+ '0x1',
|
|
|
+ 'dex',
|
|
|
+ 'swap_script',
|
|
|
+ [],
|
|
|
+ [
|
|
|
+ 'sTSuZ4bxDvdClOYn0lGbY7fHQqZzX5hoKSn+qahHRNI=',
|
|
|
+ 'jkczvavPfUr8PRTw3UbJv1L7D86eS5lsk54ZW4vIkdk=',
|
|
|
+ 'QEIPAAAAAAA=',
|
|
|
+ 'AdWGAQAAAAAA',
|
|
|
+ ],
|
|
|
+ )
|
|
|
+ const signed = await this.wallet.createAndSignTx({
|
|
|
+ msgs: [msg],
|
|
|
+ })
|
|
|
+ const broadcast = await this.lcd.tx.broadcast(signed)
|
|
|
+ console.log(broadcast)
|
|
|
+ }
|
|
|
+
|
|
|
+ async stakeInit() {
|
|
|
+ const msg = new MsgDelegate(
|
|
|
+ 'init1kdwzpz3wzvpdj90gtga4fw5zm9tk4cyrgnjauu', // delegator address
|
|
|
+ 'init18sj3x80fdjc6gzfvwl7lf8sxcvuvqjpvcmp6np', // validator's operator addres
|
|
|
+ '100000uinit', // delegate amount
|
|
|
+ )
|
|
|
+ }
|
|
|
+}
|