In Uniswap v4 you have to call the poolKeys function on the positionManager contract, which takes only one argument (poolId of type bytes25) and returns an array which contains currency0, currency, fee, tickSpacing, and hooks.
Here is a function in JavaScript:
import { slice } from "viem"; // Get the keys of a pool (currency0, currency1, fee, tickSpacing, hooks) export const getPoolKeys = async (positionManager, poolId) => { try { const poolIdBytes25 = slice(poolId, 0, 25); const [currency0, currency1, fee, tickSpacing, hooks] = await positionManager.read.poolKeys([poolIdBytes25]); return { currency0, currency1, fee, tickSpacing, hooks, }; } catch (error) { console.error("Error fetching pool keys:", error); return null; } };
In the function above poolId is taken as bytes32 and sliced using the slice function from viem.
You can find the addresses of all positionManager contracts in Uniswap v4 docs.