1

Hi I have 2 ERC20 tokens deployed and I am trying to make a pool using Uniswap V3. When I deploy my createUniswapPool.js file I get an error. I have shared the error, createUniswapPool.js, and the expected output below

Error:


SyntaxError: Unexpected token I in JSON at position 0
    at JSON.parse (<anonymous>)
    at main (/Users/.../Desktop/.../uniswapv2-pug/createUniswapPool.js:22:18)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Code createUniswapPool.js:

const { ethers } = require('ethers')
const axios = require('axios')
require('dotenv').config()

const UNISWAP_V3_FACTORY_ADDRESS = '0x1F98431c8aD98523631AE4a59f267346ea31F984'

const GOERLI_PROVIDER = new ethers.providers.JsonRpcProvider(process.env.INFURA_API_KEY)
const WALLET_ADDRESS = process.env.WALLET_ADDRESS
const WALLET_SECRET = process.env.WALLET_SECRET
const PUG_COIN_ADDRESS = '0xA4a0E3e8bBec6C56Ea121819324652bf0cCB32b9'
const POLY_COIN_ADDRESS = '0xBDfA1b5E41229B865037f001f5051ce47D075605'

const wallet = new ethers.Wallet(WALLET_SECRET)
const connectedWallet = wallet. connect(GOERLI_PROVIDER)

async function main() {
// setup V3 Factory

const apiKey = 'MY_OWN_ETHERSCAN_KEY' // create account on etherscan and enter API key
const url = 'https://api.etherscan.io/api?module=contract&action=getabi&address=${UNISWAP_V3_FACTORY_ADDRESS}&apikey=${apiKey}'
const res = await axios.get(url)
const abi = JSON.parse(res.data.result)

const factoryContract = new ethers.Contract(
    UNISWAP_V3_FACTORY_ADDRESS,
    abi,
    GOERLI_PROVIDER
)

// create the pool

const tx = await factoryContract.Contract.connect(connectedWallet).createPool(
    PUG_COIN_ADDRESS,
    POLY_COIN_ADDRESS,
    500 // can change fee 
)


const receipt = await tx.wait()
console.log('receipt', receipt)

//get pool address
const newPoolAddress = await factoryContract.getPool( 
     PUG_COIN_ADDRESS,
    POLY_COIN_ADDRESS,
    500 // BASIS POINT FEE - can change fee betweeb 500/1000 
)
console.log('newPoolAddress', newPoolAddress)



}

main() ```


Command I ran : ```node createUniswapPool.js```
1
  • From the error you can see problematic line is: const abi = JSON.parse(res.data.result), I suspect you got an error message instead of contract ABI. Can you put a console.log(res.data.result) to the line before that to debug? Commented Mar 9, 2023 at 8:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.