【发布时间】:2022-11-13 04:36:04
【问题描述】:
我是使用区块链的新手,在尝试从 Uniswap 获取合同时遇到问题。我一直在关注他们在 V3 上的文档,但我无法克服这个“abi.map 不是函数”错误。当我将 ABI 输出到控制台时,看起来我正确地恢复了 ABI,但是当我尝试使用它来初始化合同时,我得到了这个错误。
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)
})
【问题讨论】:
-
如果它期望 abi.map 是一个函数,那么它必须期望 abi 是一个数组(它不是)。检查github.com/ethers-io/ethers.js/issues/1238
-
我已经尝试了他们在那里建议的修复程序,但找不到找回模块。我检查了文件目录并且模块在那里并且我指向正确的位置。
标签: javascript cryptography ethers.js uniswap