I'm trying to invoke the following solidity function from ethersjs (it takes another contract as argument):
function getReservesData(IPoolAddressesProvider provider) public view override ...
I tried this code:
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);
I get the following error:
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)
Probably I'm missing some key information on how to pass a contract type parameter.
The Solidity function accepts a Solidity interface, which is ABI decoded from the address
type.
So in JS, you need to pass the pool address as a string
- not the ethers.js
instance of Contract
.
const poolAddress = "0x123...";
await contract.getReservesData(poolAddress);