I want to call Quoter Contract on BSC Mainnet which is deployed already.
I'm using HardHat or Foundry to fork Mainnet specific blocknumber, here is HardHat Config JS:
module.exports = {
solidity: "0.8.19",
networks: {
hardhat: {
forking: {
// url: Also Try Using QuickNode API,
url: "http://127.0.0.1:8540",// Local Server is running Geth Service on 8540 port
blockNumber: 31723542,//Trying to fork this blockNumber
chainId: 56
}
}
}
};
Or Using Foundry Anvil:
anvil --fork-url QuickNode's_HTTP_EndPoint --fork-block-number 31723542 --chain-id 56
My Test JS File
const { Web3 } = require('web3');
const {ethers } = require('ethers')
//Quoter Address ABI JSON
jsonFile = "./bsc-quoter.json";
parsed = JSON.parse(fs.readFileSync(jsonFile));
var bscAbi = parsed
//bsc-quoter
bscQuoterAddress = '0xB048Bbc1Ee6b733FFfCFb9e9CeF7375518e25997'
const rpcURL = "http://127.0.0.1:8545"//Using Local HardHat or Foundry Fork
var web3 = new Web3(new Web3.providers.HttpProvider(rpcURL));
const provider = new ethers.providers.JsonRpcProvider(rpcURL)
const bscQuoter = new ethers.Contract(
bscQuoterAddress,
bscAbi,
provider
)
const main = async() => {
//Just Random Pick a V3Pool Address
const params = {
tokenIn:"0x55d398326f99059fF775485246999027B3197955",
tokenOut:"0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
amountIn:"91188",
fee:500,
sqrtPriceLimitX96:0
}
const amountOut = await bscQuoter.callStatic.quoteExactInputSingle(
params
)
console.log('amountOut',amountOut['amountOut'].toString())
}
main()
This is BSC Mainnet Quoter Contract Address (Which is already deployed in previous block)
0xB048Bbc1Ee6b733FFfCFb9e9CeF7375518e25997
Then, I Just Call the js:
npx hardhat run ./quoter.js
//Or
npx hardhat run ./quoter.js --network localhost
It failed.
HardHat Fork Terminal log:
eth_accounts
eth_call
WARNING: Calling an account which is not a contract
From: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
To: 0xb048bbc1ee6b733fffcfb9e9cef7375518e25997
This Quoter is a Contract , I don't know why it failed.
But when forking without blocknumber, it success.