I'm trying to get a factory address for Uniswap on base network, unfortunately I'm not able to locate this address anywhere and I'm kind of desperate as without it I'm not able to try my code that will search for new pairs on Uniswap. I found the router address and trying to figure out how from this address can I get the factory address that I need.
I found this post but the answer provided really didn't tell much about how to implement it in the code...
const Web3 = require('web3').default;
const web3 = new Web3('https://mainnet.base.org');
// Router contract ABI (This is a simplified ABI containing only the factory method)
const routerAbi = [
{
"constant": true,
"inputs": [],
"name": "factory",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
];
// Router contract address
const routerAddress = '0x198EF79F1F515F02dFE9e3115eD9fC07183f02fC';
// Create a new contract instance
const routerContract = new web3.eth.Contract(routerAbi, routerAddress);
// Fetch the factory address
async function getFactoryAddress() {
try {
const factoryAddress = await routerContract.methods.factory().call();
console.log('Factory Address:', factoryAddress);
} catch (error) {
console.error('Error fetching factory address:', error);
}
}
getFactoryAddress();
I have this error unfortunately...
Error:
Error fetching WETH address: ContractExecutionError: Error happened while trying to execute a function inside a smart contract
at Web3RequestManager._isReverted (/root/base-liquidity-snipe/node_modules/web3-core/lib/commonjs/web3_request_manager.js:311:19)
at Web3RequestManager._processJsonRpcResponse (/root/base-liquidity-snipe/node_modules/web3-core/lib/commonjs/web3_request_manager.js:257:42)
at Web3RequestManager.<anonymous> (/root/base-liquidity-snipe/node_modules/web3-core/lib/commonjs/web3_request_manager.js:156:29)
at Generator.next (<anonymous>)
at fulfilled (/root/base-liquidity-snipe/node_modules/web3-core/lib/commonjs/web3_request_manager.js:21:58)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
innerError: [Eip838ExecutionError: execution reverted] {
innerError: undefined,
code: -32000,
receipt: undefined,
data: undefined
},
code: 310,
receipt: undefined
}
Help/advice will be much appreciated.