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

Ethereum deployment script: What’s wrong?

When it works to deploy smart contractions on Ethereum blockchain, a well -designed deployment script is Cruise. In this article, we will dive into question, it could be trying “console.log” studios

The problem

In your example of Snippt code, you use the instruction Module. Exports' to export Howver, you have searched a problem with the console journal states inside this script.

Javascript

Const {network} = require ('"hardhat"');

Const {

Understood,

Networkconfig,

Initial_supply,

} = require ('../ Helper-hardhat-Config "');

Export module = {

// Your HERRE deployed code

};

'

When you run your deployment script, the "console.log" items will not do so because they are placed on objectives.

Correct

To solve this problem, you need to wrap your console inside an import or conditional blocks that allows it. Here is an update version of your SNIPPT code:

Javascript

Const {network} = require ('"hardhat"');

Const {

Understood,

Networkconfig,

Initial_supply,

} = require ('../ Helper-hardhat-Config "');

Export module = () => {

Console.log ("Deployment started!");

If (Nework.name === 'Mainnet') {

console.log ("deployed on Mainnet!");

} else if (developmentchains.cluds (network.name)) {

Console.log ("Deploiarnate in the development chain!");

}

Const {accounts, getContractionAddress} = require ('../ Helper-hardhat-config');

// Your contractor code deployed.

};

'

In this updated version:

  • We are articlesConsole.Loginside an arrow function ( () => {} `) to assess.

  • We are an import in the access “acuntes” and “tractaddress”.

3 and 3

Best practices *

To avoid similar problems in the future, make a comment for:

  • Use export items in functions or a block that allow the evaluation.

  • Avoid the console of interior import states or Wen’s evaluation expressions.

  • Consider using a separate module for your contact contact deployed to keep it and maintain.

ethereum reliable bitcoin wealth

Leave a Reply

Shopping cart

0
image/svg+xml

No products in the cart.

Continue Shopping