-
Hi there, Can somebody please give me a plain English explanation of the following code in 001-deploy-fund-me.js module.exports = async ({ getNamedAccounts, deployments }) => {
const { deploy, log } = deployments
const { deployer } = await getNamedAccounts()
const chainId = network.config.chainId
} I'm confused by the syntax and also it seems there is a lot going on behind the scenes with hardhat and the deploy plugin. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
{ getNamedAccounts, deployments } is just a shorthand for The above essentially "extracts" getNamedAccounts and deployments from Hardhat
Further, for it to be used in other scripts, we have to declare it as a "module", i.e. module.exports (this is a Node.js thing, you will comprehend when you go through a Node.js course, but for now just know that it is a module primarily used for exporting, which can then be used in other scripts)
Similarly, the above "extracts" deploy and log from deployments
In hardhat.config:
so, getNamedAccounts is just a getter provided to us. Out of which, we "extract" deployer
This is equivalent to, network->config->chainId for accessing the chainId. Refer https://hardhat.org/hardhat-network/docs/reference#config |
Beta Was this translation helpful? Give feedback.
-
Okay. In the first line we are creating an asyncronous function, and exporting it. This is the same as creating a function and exporting it
However, how hardhat-deploy works is that, we pass in an instance of the hardhat-runtime-environment/hre ( same as doing
But then instead of passing the entire hre, we only want two objects from hre that is
|
Beta Was this translation helpful? Give feedback.
{ getNamedAccounts, deployments } is just a shorthand for
const { getNamedAccounts, deployments } = hre
The above essentially "extracts" getNamedAccounts and deployments from Hardhat
async
declares the function as an asynchronous one, which lets us useawait
Further, for it to be used in other scripts, we have to declare it as a "module", i.e. module.exports (this is a Node.js thing, you will comprehend when you go through a Node.js course, but for now just know that it is a module primarily used for exporting, which can then be used in other scripts)
Similarly, the above "extracts" deploy and log from deployments