Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

222
Views
¿Cómo esperar si no hay funciones?

Estoy tratando de ejecutar un código javascript simple directamente desde la documentación, pero por alguna razón está dando como resultado un 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);

¿Qué me podría estar perdiendo? Gracias.

PD: este código se toma directamente de la documentación: https://docs.terra.money/docs/develop/sdks/terra-js/common-examples.html

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Envuelva su código en una función asíncrona o en IIFE asíncrono

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!