Uniswap
我在哪裡放置 Uniswap 教程中的程式碼?
我正在關注這個 Uniswap 教程。我已經按照第一步說明建立了一個項目。在那個項目中,我還建立了一個安全帽項目,並且我已經分叉了主網,我可以從安全帽節點使用它。
我被困在 Importing Ethers 和 V3 SDK 部分。我不知道程式碼在哪裡。我嘗試將該程式碼輸入到 Hardhat 控制台,但出現以下錯誤:
$ 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
有人可以向我解釋一下教程中的程式碼應該去哪裡嗎?
那就是程式碼,它在你的 .js 文件中。在教程結束時,腳本如下所示:
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); });