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

149
Views
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
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!