price_oracle.js
/* Main function because we like async and await  */
Main function because we like async and await
Main function because we like async and await
async function job(nextJob){
  console.log('Starting Price Oracle Bot.')
  const response = await fetch('https://api.coingecko.com/api/v3/simple/price?ids=expanse&vs_currencies=usd');
  const data = await response.json();
  const wei = utils.parseEther(data.expanse.usd.toString());
  console.log(`Setting USD Price : ${data.expanse.usd}`);
  const tx = await CONTRACT.setPriceUsd(wei, { gasPrice: gasPrice, gasLimit: gasLimit});
  await waitForTx(provider, tx.hash)
  console.log(`Finished conversion. Next job @ ${nextJob}`)
}
async function job ( nextJob ) { console . log ( 'Starting Price Oracle Bot.' ) const response = await fetch ( 'https://api.coingecko.com/api/v3/simple/price?ids=expanse&vs_currencies=usd' ) ; const data = await response . json ( ) ; const wei = utils . parseEther ( data . expanse . usd . toString ( ) ) ; console . log ( ` ${ data . expanse . usd } ` ) ; const tx = await CONTRACT . setPriceUsd ( wei , { gasPrice : gasPrice , gasLimit : gasLimit } ) ; await waitForTx ( provider , tx . hash ) console . log ( ` ${ nextJob } ` ) }
Main function because we like async and await
Main function because we like async and await
//get usd price //set use price