I'm trying to write some Javascript code to query Fantom DEXes to find out the price wFTM in various wFTM / USDC liquidity pools and I'm a bit lost as to what contract method to call.

I'm starting with Spookyswap and I'm thinking what I need to do is first get a reference to the Factory Contract, and then call getPair() on it with the contract addresses for wFTM (0x21be370D5312f44cB42ce377BC9b8a0cEF1A4C83) and USDC (0x04068DA6C83AFCFA0e13ba15A6696662335D5B75)


When I call that method, I get a reference to this contract


which has two variables



which logically seem like the variables I want, but I'm not really sure that's correct and I have no idea how to translate them into USDC.

There's probably something very obvious I'm not grokking, so any help will be much appreciated. This is my first attempt to learn web3 by creating something on my own.


1 Answer 1


Since spookyswap is pretty much uniswapv2 its probably best to reference the uniswapv2 docs for pricing https://docs.uniswap.org/protocol/V2/reference/smart-contracts/pair#getreserves

For any ERC20/stable pair you should be able to do something along these lines. Get the reserves and calculate the spot price

    uReserves = await uPair0.methods.getReserves().call()
    uReserve0 = uReserves[0] //dai
    uReserve1 = uReserves[1] //eth
    priceEth = (uReserve0/uReserve1) //dai per eth

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.