Reach Markets

Ethereum’s deployment command series: What goes wrong?

When Introducing Smart Contracts, a Well-Designed Deployment Command series is crucial to success. In this article, we will deepen the thing that can be created as you try to use “console.log” statements after the module’s export.

Topic

Use the example code to use the module.xports statement to export the contract introduced. However, you have met the problem with console locks inside this script.

`JavaScript

Const {Network} = insist ('"hardhat");

Const {

Development Chains,

Networkconfig,

Original,

} = Require ('"../ helper-hardhat-config");

Module.exports = {

// launched your contract code

};

When you run a set of commissioning commands, the console.los are not executed as they are placed outside the export object.

Repair

In order to solve this problem, you need to wrap the console locks in the importation or a conditional block that can be used to evaluate them. HERE’S AN UPDATED VERSION OF YOUR CODE HEAD:

`JavaScript

Const {Network} = insist ('"hardhat");

Const {

Development Chains,

Networkconfig,

Original,

} = Require ('"../ helper-hardhat-config");

Module.exports = () => {

Console.log ('Deployment Started!');

if (network.name === 'mounts') {

Console.log ('placed mitted!');

} Else IF (Developmentchains.include (Network.name)) {

Console.log ('moved to the development chain!');

}

Const {accounts, getcontractaddress} = insist ('.

// launched your contract code

};

In this updated version:

  • Snake Console.Log phrases inside the Arrow Function (() => {}`), which allows us to judge them.

  • We use the importation to use “Accounts” and “GetContractDress”.

  • Conditional Block Checks whether are entering a specific network (mainnet or development chain) before taking the contract code.

Best Practices

Ethereum: My deploy script won't run. Any `console.log` after `module.exports` won't work

To Avoid Similar Questions in the Future, Remember:

  • Use export orders in functions or other groups that allow the Evaluation.

  • Avoid console locks within or when evaluating expression.

  • Consider the use of a separate module for the contract logic introduced to keep it organized and maintained.

RUGPULL WORMHOLE MULTICHAIN

Leave a Reply

Your email address will not be published. Required fields are marked *