Ethers.js: Solidity method arguments of type "contract": Error: invalid address or ENS name

Ethers.js: Solidity method arguments of type "contract": Error: invalid address or ENS name

我正在尝试从 ethersjs 调用以下 solidity 函数 (它以另一个合同为参数):

function getReservesData(IPoolAddressesProvider provider) public view override ...

我试过这段代码:

 const provider = new ethers.providers.JsonRpcProvider(env.network);
 
 const contract = new ethers.Contract(
            '0x...'
            [ ...], // contract json abi
            provider
        );

const poolAddressProvider = new ethers.Contract(
            '0x...'
            [ ...], // pool address provider json abi
            provider
        );

await contract.getReservesData(poolAddressProvider);

我收到以下错误:

core.mjs:6484 ERROR Error: Uncaught (in promise): Error: invalid address or ENS name (argument="name", value="[object Object]", code=INVALID_ARGUMENT, version=contracts/5.5.0)
Error: invalid address or ENS name (argument="name", value="[object Object]", code=INVALID_ARGUMENT, version=contracts/5.5.0)

可能我遗漏了一些关于如何传递合约类型参数的关键信息。

Solidity 函数接受一个 Solidity 接口,它是从 address 类型解码而来的 ABI。

因此在 JS 中,您需要将池地址作为 string 传递 - 而不是 Contract.

ethers.js 实例
const poolAddress = "0x123...";
await contract.getReservesData(poolAddress);