Skip to content

What is the logic behind the variables put in {}/extrapolated variables? #313

Answered by PatrickAlphaC
cipher222 asked this question in Q&A
Discussion options

You must be logged in to vote

This is actually called Object Destructuring in javascript(sorry, I think I called it extrapolation).

Example 1

On this line:

module.exports = async ({ getNamedAccounts, deployments }),

When we call yarn hardhat deploy, we actually pass an hre or "hardhat runtime environment" variable to the async function described here. So you could think of it as doing:

module.exports = async (hre) {

Now, the hre object has 2 objects we care about, namely getNamedAccounts and deployments. Since we know we only want those, we can just pull them out of hre, or "destructure" them like so:

module.exports = async (hre) {
  { getNamedAccounts, deployments } = hre

Javascript actually just allows us to do it r…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@PatrickAlphaC
Comment options

@cipher222
Comment options

@mattjaf
Comment options

Answer selected by PatrickAlphaC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants