Skip to content

Instantly share code, notes, and snippets.

@earthchie
Last active February 22, 2024 09:19
Show Gist options
  • Save earthchie/bc528f3bcbc1ef00b43c40ab9238cbd2 to your computer and use it in GitHub Desktop.
Save earthchie/bc528f3bcbc1ef00b43c40ab9238cbd2 to your computer and use it in GitHub Desktop.
const ethers = require('ethers');
const provider = new ethers.providers.JsonRpcProvider('https://bsc-dataseed.binance.org/');
// you can find pair address from Factory Contract, method getPair(token1Addr, token2Addr).
let Contract = {
PancakePair: new ethers.Contract('0xb694ec7C2a7C433E69200b1dA3EBc86907B4578B',['function getReserves() public view returns (uint112 _reserve0, uint112 _reserve1, uint32 _blockTimestampLast)'], provider),
TwindexPair: new ethers.Contract('0xC789F6C658809eED4d1769a46fc7BCe5dbB8316E',['function getReserves() public view returns (uint112 _reserve0, uint112 _reserve1, uint32 _blockTimestampLast)'], provider)
}
provider.on('block', async (blockNumber) => {
const pancakeReserves = await Contract.PancakePair.getReserves();
const at_pancake = pancakeReserves[1] / pancakeReserves[0];
console.log(`Pancake 1 DOP = ${at_pancake} BUSD`);
const twindexReserves = await Contract.TwindexPair.getReserves();
const at_twindex = twindexReserves[1] / twindexReserves[0];
console.log(`Twindex 1 DOP = ${at_twindex} BUSD`);
});
@sullibar
Copy link

I got the error "cannot estimate gas" on some coins, any idea?

@earthchie
Copy link
Author

No idea. Because this script should be read-only mode, which should not cost any gas.

@javaverse
Copy link

I got the error "cannot estimate gas" on some coins, any idea?

try to change token to other one.

@rafaelfaria
Copy link

I get exactly the same message "Unhandled Rejection (Error): cannot estimate gas; transaction may fail or may require manual gas limit"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment