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
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.
-
When we use hre.ethers.getContractFactory() ? Using hre here is necessary??– HacekCommented Feb 7, 2023 at 7:07
-
ethers.getContractFactory() is a function within the ethers library, and can be called directly without the "hre." prefix. 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??– HacekCommented 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. 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.– HacekCommented Feb 7, 2023 at 7:36