Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

220
Visualizações
how to await if there are no functions?

I am trying to run a simple javascript code straight from the documentation, but for some reason it's resulting in an error-

"SyntaxError: await is only valid in async functions and the top level bodies of modules"

const { MnemonicKey,Coin,MsgSwap,LCDClient,MsgExecuteContract } = require('@terra-money/terra.js');

const lcd = new LCDClient({
  URL: 'https://lcd.terra.dev',
 // URL: 'https://falling-empty-waterfall.terra-mainnet.quiknode.pro/94818b47fef9194193d08f7ffdc9e90ffdcdee17/',
  chainId: 'columbus-5'
});


const mk = new MnemonicKey({
    mnemonic: 'mnemo',
})


// UST <> SCRT
const pool = "terra1tq4mammgkqrxrmcfhwdz59mwvwf4qgy6rdrt46";

// Fetch the number of each asset in the pool.
const { assets } = await lcd.wasm.contractQuery(pool, { pool: {} });

// Calculate belief price using pool balances.
const beliefPrice = (assets[0].amount / assets[1].amount).toFixed(18);

// Swap 1 UST to SCRT with 1% slippage tolerance.
const terraSwap = new MsgExecuteContract(
  wallet.key.accAddress,
  pool, 
  {
    swap: {
      max_spread: "0.01",
      offer_asset: {
        info: {
          native_token: {
            denom: "uusd",
          },
        },
        amount: "1000000",
      },
      belief_price: beliefPrice,
    },
  },
  new Coins({ uusd: '1000000' }),
);

const tx = await wallet.createAndSignTx({ msgs: [terraSwap] });
const result = await lcd.tx.broadcast(tx);

console.log(result);

What could I be missing? Thank you.

P.s this code is taken straight from the documentation - https://docs.terra.money/docs/develop/sdks/terra-js/common-examples.html

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Wrap your code in async function or in async IIFE

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda