0

As per my understanding, if we want to get or interract with an already deployed contract, we can use this ethers.getContractAt() function.

But since it's already deployed, can't we just give the contract name and address to get it? Is it compulsory to have the contract (here, ILendingPoolAddressesProvider.sol) code in my local folder too?

And also, why am I attaching an account with it, since it has been deployed already?

There might be some mistakes in my basic understanding. Kindly explain.

const lendingPoolAddressesProvider = await ethers.getContractAt(
            "ILendingPoolAddressesProvider",
            "0xB53C1a33016B2DC2fF3653530bfF1848a515c8c5",
            account
            )

1 Answer 1

0

If you look at the documentation of ethers.getContractAt you will find this:

function getContractAt(name: string, address: string, signer?: ethers.Signer): Promise<ethers.Contract>;

Note: If there is no signer available, getContractAt returns read-only contracts.

The '?' in 'signer?: ethers.Signer' means that argument is optional. So you don't need to provide 'account'.

And by giving it the name of the contract. ether knows what ABI to use to talk to this contract (i.e. what function to use to talk to the contract). So name and address, or abi and address are the bare minimum.

Hope this helps!

1
  • Got it.. but is it necessary to also have that contract ("name") code in our local development as the tutorial I have been following by Patrick Collins, he has given the name let say, "ILendingPool" in the getContractAt() function and also copied the code of ILendingPool.sol from aave website and stored in contracts/interfaces ... so is copying the code necessary? can't it just find it from the already deployed contract itself using the name? Nov 7 at 7:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.