3

I want to know everything what ethers.getContractFactory() does. It's parameters, when should I use it, difference between ethers.getContractFactory() and ethers.getContractAt().

1 Answer 1

3

Here is the difference:

ethers.getContractFactory() returns a JavaScript object that represents a smart contract factory. You can use this object to deploy new instances of the smart contract.

ethers.getContractAt() returns an instance of a smart contract that has already been deployed to the Ethereum network. It takes the Ethereum address of an existing smart contract as an argument and returns an object that represents this specific instance of the contract.

In summary, ethers.getContractFactory() is used to deploy a new smart contract, while ethers.getContractAt() is used to interact with an existing smart contract on the Ethereum network.

9
  • When we use hre.ethers.getContractFactory() ? Using hre here is necessary??
    – Hacek
    Commented Feb 7, 2023 at 7:07
  • ethers.getContractFactory() is a function within the ethers library, and can be called directly without the "hre." prefix.
    – f22daniel
    Commented Feb 7, 2023 at 7:10
  • In hardhat-ethers we have these function: function getContractFactory(name: string, signer?: ethers.Signer): Promise<ethers.ContractFactory>; function getContractFactory(name: string, factoryOptions: FactoryOptions): Promise<ethers.ContractFactory>; , when we write ethers.getContractFactory() we give only contract name, like getContractFactory("Contract_name"), why we don't give the another parameter too as the helper function states??
    – Hacek
    Commented Feb 7, 2023 at 7:14
  • I am not sure. Maybe create a question on it's own for this topic. I am not that well versed in Hardhat. I hope someone else will be able to help you.
    – f22daniel
    Commented Feb 7, 2023 at 7:17
  • Signers are connected by default with contract and contractFactory, right? Means we don't need to add signer.
    – Hacek
    Commented Feb 7, 2023 at 7:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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