8

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!

maskara
  • 329
  • 1
  • 2
  • 12

2 Answers2

16

The getContractAt() function is part of the hardhat-ethers plugin for Hardhat, expanding the ethers object.

It's not a part of the core Ethers package, so it's not included in their documentation.

Hardhat docs mentioning the plugin: https://hardhat.org/plugins/nomiclabs-hardhat-ethers.html#helpers

Petr Hejda
  • 40,554
  • 8
  • 72
  • 100
  • will hit this issue after added this line `Module not found: Can't resolve 'async_hooks' in 'C:\Users\nick_\VSCodeProjects\xxx\nft\node_modules\undici\lib\api'`. – John Joe Jan 25 '23 at 13:13
4

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 Name",
        deployed contract address
    );
sherpya
  • 4,890
  • 2
  • 34
  • 50
Muhammad Hassan
  • 424
  • 3
  • 5