1

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.

1 Answer 1

0

const Web3 = require('web3').default; const web3 = new Web3('https://mainnet.base.org');

const abi = require('./uniswapV2RouterABI.json').abi;

const router = '0x4c36388be6f416a29c8d8eee81c771ce6be14b18'; //Pool address const routerContract = new web3.eth.Contract(abi, router);

async function getFactoryAddress() { try { let factoryAddress = await routerContract.methods.factory().call(); console.log(factoryAddress); } catch (error) { console.error("Error fetching factory address:", error); } }

getFactoryAddress();

I was able to find the factory address by using a pool contract from the Dex I wanted a factory address for. Secondary solution is to checkin the pool contract manually on basescan/etherscan and then just click on the contract creator/deployer, this is your factory address :-).

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.