andrea simeoni
andrea simeoni

Reputation: 186

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

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.

Upvotes: 0

Views: 1860

Answers (2)

SinisaT90
SinisaT90

Reputation: 92

Use "0x123..." instead of '0x123...'. For some reason it won't parse an address as a string with single quotes.

Upvotes: 0

Petr Hejda
Petr Hejda

Reputation: 43581

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);

Upvotes: 2

Related Questions