0

I'm following this Uniswap tutorial. I have set up a project following the First Steps instructions. Within that project, I also set up a Hardhat project and I've forked the mainnet, which I can use from the hardhat node.

I'm stuck on the Importing Ethers and the V3 SDK part. I don't know where the code goes. I tried typing that code into the Hardhat console, but I get the following error:

$ npx hardhat console
Welcome to Node.js v16.13.0.
Type ".help" for more information.
> import { ethers } from "ethers";
import { ethers } from "ethers";
^^^^^^

Uncaught:
SyntaxError: Cannot use import statement inside the Node.js REPL, alternatively use dynamic import

Can someone explain to me where is the code from the tutorial supposed to go?

1 Answer 1

0

That is code, it goes in your .js file. At the end of the tutorial the script looks like this:

import { ethers } from "ethers";//HERE IT IS
import { Address } from "cluster";

const provider = new ethers.providers.JsonRpcProvider("<YOUR_ENDPOINT_HERE>");

const poolAddress = "0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8";

const poolImmutablesAbi = [
  "function factory() external view returns (address)",
  "function token0() external view returns (address)",
  "function token1() external view returns (address)",
  "function fee() external view returns (uint24)",
  "function tickSpacing() external view returns (int24)",
  "function maxLiquidityPerTick() external view returns (uint128)",
];

const poolContract = new ethers.Contract(
  poolAddress,
  poolImmutablesAbi,
  provider
);

interface Immutables {
  factory: Address;
  token0: Address;
  token1: Address;
  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);
});
1
  • 1
    Thanks, this helped. Also, I think this is TypeScript, so I had to follow the following guide as well. Commented Nov 24, 2021 at 16:20

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.