Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

150
Vistas
How can I make a request to get data about the currency value?

Hello, guys, could you help me, please? I have javascript code to get currency value data, but my code is not working correctly and the "updatePrice" function does not work and does not update the price data. What is my mistake?

JS-code

const CONTRACTS = {
    'PCS_ROUTER' : '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D',
    'WBTC' : '0xBb2b8038a1640196FbE3e38816F3e67Cba72D940',
    'USDT' : '0x0d4a11d5EEaaC28EC3F61d100daF4d40471f1852'
}
const provider = new ethers.providers.JsonRpcProvider('INFURIA_API');

const router = new ethers.Contract( CONTRACTS['PCS_ROUTER'], ['function getAmountsOut(uint amountIn, address[] memory path) public view returns (uint[] memory amounts)', 'function symbol() external view returns (string memory)'], provider);

const main = async function() {
    updatePrice('main-text-wbtc', 'WBTC');
    setTimeout(main, 5000);
}   

const updatePrice = async function(elementId, contracts) {
    let price = await router.getAmountsOut(ethers.utils.parseUnits('1.0', 'ether'),[CONTRACTS[contracts],CONTRACTS['USDT']]);
    document.getElementById(elementId).innerHTML = parseFloat(ethers.utils.formatEther(price[1])).toFixed(4).toLocaleString("en-US");
}
main();

HTML-code

   <tr>
      <td><span id="main-text-wbtc">0.00</span></td>
      <td><p>WBTC</p></td>
   </tr>
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda