Documentation for ethers.getContractAt()

Viewed 4305

Can somebody please point me to the documentation (official or otherwise ) that explains the function ethers.getContractAt():

the original context of this is as follows:

vrfCoordinator = await ethers.getContractAt('VRFCoordinatorMock', VRFCoordinatorMock.address, signer)

and the full code can be found here... https://github.com/PatrickAlphaC/all-on-chain-generated-nft/blob/main/deploy/02_Deploy_RandomSVG.js

In the absence of such documentation, an explanation would be much appreciated. Thank you!

2 Answers

Basically, it is doing the same thing, that attach do but in one line. i.e you can actually interact with an already deployed contract.

For reference below is the code if you are using attach

let xyzContract = await hre.ethers.getContractFactory("Name of the contract");
let xyzContractInstance = xyzContract.attach('Address of the contract');

You can accomplish the same thing in one line via getContractAt() when using hardhat

let xyzContractInstance = await hre.ethers.getContractAt(
        "Contract Address",
        deployed contract address
    );
Related