Search
Close this search box.

Ethereum Deployment Script: What’s Going Wrong?

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

When it comes to deploying smart contracts on the Ethereum blockchain, a well-crafted deployment script is crucial to success. In this article, we’ll dive into an issue that can arise when trying to use console.log statements after exporting your module.

The Problem

In your example code snippet, you’re using the module.exports statement to export your deployed contract. However, you’ve encountered an issue with the console log statements within this script.

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

constant {

dev_strings,

network_config,

SUPPLY_INITIAL,

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

module.exports = {

// Your deployed contract code here

};

When you run your deployment script, the console.log statements will not be executed because they are located outside of an export object.

The solution

To resolve this issue, you must enclose your console log statements within an import statement or conditional block that allows them to be evaluated. Here is an updated version of your code snippet:

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

constant {

dev_strings,

network_config,

SUPPLY_INITIAL,

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

module. exports = () => {

console. log('Deployment started!');

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

console. log('Deployed to main network! ');

} else if (devchains.includes(name.network)) {

console.log('Deployed to devchain!');

}

const { accounts, getContractAddress } = require('../helper-hardhat-config');

// Your deployed contract code here

};

In this updated version:

Best Practices

To avoid similar issues in the future, be sure to:

Leave a Reply

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