I'm new to working with blockchain and I'm having a problem trying to get the contract from Uniswap. I've been following their docs on V3 but I can't get past this "abi.map is not a function" error. When I output the ABI to the console, it looks like I get the ABI back correctly but when I try to use it to initialize the contract I get this error.
import { ethers } from 'ethers'
const ABI = require('@uniswap/v3-core/artifacts/contracts/interfaces/IUniswapV3Pool.sol/IUniswapV3Pool.json')
console.log(ABI)
const provider = new ethers.providers.JsonRpcProvider('https://mainnet.infura.io/v3/Your Address Here;p')
const poolAddress = '0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8'
const poolContract = new ethers.Contract(poolAddress, ABI, provider)
interface Immutables {
factory: string
token0: string
token1: string
fee: number
tickSpacing: number
maxLiquidityPerTick: number
}
async function getPoolImmutables() {
const [factory, token0, token1, fee, tickSpacing, maxLiquidityPerTick] = await Promise.all([
poolContract.factory(),
poolContract.token0(),
poolContract.token1(),
poolContract.fee(),
poolContract.tickSpacing(),
poolContract.maxLiquidityPerTick(),
])
const immutables: Immutables = {
factory,
token0,
token1,
fee,
tickSpacing,
maxLiquidityPerTick,
}
return immutables
}
getPoolImmutables().then((result) => {
console.log(result)
})
This error will go away if you delete everything in the abi up to the first square bracket after "abi". So for IUniswapV3Pool.json, instead of:
It should be:
And don't forget to delete everything up to the last square bracket at the end of the file as well.