zkdomains

Native Terra Swaps

Aug 27th, 2023
485
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 0.81 KB | Cryptocurrency | 0 0
  1. import {
  2.     Coin, LCDClient, MnemonicKey, MsgSwap
  3. } from '@terra-money/terra.js'
  4. import axios from 'axios'
  5.  
  6. async function main() {
  7.  
  8.     const mk = new MnemonicKey({
  9.         mnemonic: '',
  10.     })
  11.  
  12.     let chainID = 'columbus-5'
  13.  
  14.     let gasPrices = await axios('https://columbus-fcd.terra.dev/v1/txs/gas_prices')
  15.     gasPrices = gasPrices.data
  16.  
  17.     const lcd = new LCDClient({
  18.         URL: 'https://lcd.terra.dev',
  19.         chainID: 'columbus-5',
  20.         gasAdjustment: 2,
  21.         gasPrices,
  22.         isClassic: true
  23.     })
  24.  
  25.     const wallet = lcd.wallet(mk)
  26.  
  27.     try {
  28.  
  29.         const swap = new MsgSwap(
  30.             wallet.key.accAddress,
  31.             new Coin('usdr', '100000'),
  32.             'uusd'
  33.         )
  34.  
  35.         const tx = await wallet.createAndSignTx({
  36.             msgs: [swap],
  37.             chainID,
  38.         })
  39.        
  40.         await lcd.tx.broadcastSync(tx, chainID)
  41.  
  42.     } catch (e) {
  43.         console.log(e)
  44.     }
  45.  
  46. }
  47.  
  48. main().catch()
  49.  
Advertisement
Add Comment
Please, Sign In to add comment