I have developed an app that swaps eth for dai in ropsten network using uniswap, but when I get to check the price of eth in dai I get a strange value, 95.9...
Is it beacuse I am in Ropsten test Network? I can't manage to figure out if it is because of that or If i am doing my calculations wrong, so I'd appreciate any help you guys could give me. The actual line where I check the price of 1 ether in dai goes like this (node.js):
await exchangeContract.methods.getEthToTokenInputPrice(web3.utils.toWei('1', 'Ether')).call()
Also I have developed a test on the mainnet, but get a strange result too:
const web3 = new Web3('https://mainnet.infura.io/v3/c1d623fecf4a4ef785085de5cf9eaf18')
// Uniswap factory contract
const factoryABI = ABI(Not going to copy the line)
const FACTORY_ADDR = '0xc0a47dFe034B400B47bDaD5FecDa2621de6c4d95'
const factoryContract = new web3.eth.Contract(factoryABI,FACTORY_ADDR)
//Uniswap dai exchange contract
const exchangeAbi = ABI(Not going to copy the line)
async function checkEthPrice() {
const exchangeAddr = await factoryContract.methods.getExchange('0x09cabec1ead1c0ba254b09efb3ee13841712be14').call()
const exchangeContract = new web3.eth.Contract(exchangeAbi, exchangeAddr)
const daiAmount = await exchangeContract.methods.getEthToTokenInputPrice(web3.utils.toWei('1', 'Ether')).call()
console.log('Eth price:', daiAmount, 'DAI')
}
test = setInterval(async () => { await checkEthPrice(); }, 1000)
The result I get when executing this file: Eth price: 136478377597734366 DAI
Maybe I am not using the contract I should with dai?
Thank you everybody!