Ethereum’s placement script: What is not okay?
When it comes to placing smart contracts for the Ethereum blockchain, a well -designed placement script is very important. In this article, we will enter into the problem of trying to use console ads. Ilog after the module export.
question
In the example of the contract in which you are, use the module.exports notification in the example of the code passage. However, in this script you faced the problem of the console journal announcements.
`Javascript
Const {network} = ask (” hardhat ” ‘);
Const {
Development Chains,
NetworkConfig,
Initially_supply,
} = Ask (‘”../ hardhat-config’ ‘);
module.exports = {
// the contract code you are leaving here
};
`
When you run the placement script, the "console.log" ads will not be executed because they are located outside the export object.
Correction
To solve this problem, you must cover the ads connected in a statement of import or a conditioned block that will allow them to evaluate. Here is an updated version of the code fragment:
Javascript
Const {network} = ask (” hardhat ” ‘);
Const {
Development Chains,
NetworkConfig,
Initially_supply,
} = ask (‘”../ hardhat-config’ ‘);
module.exports = () => {
Console.log (‘Placing has begun!’);
if (network.Name === ‘Mainnet’) {
Console.log (‘placed on Mainnet!’);
} else if (developmentchains.include (network.name)) {
Console.log (“placed on the development chain!”);
}
Const {accounts, getcontractddres} = ask (‘../ helper-hardhat-config’);
// the contract code you are leaving here
};
`
In this updated version:
- We pack "console.log" statements in the arrow function (() => {}`), which allows us to appreciate them.
- We use an import ratio to access “accounts and” Getcontraddress “.
- The conditioned block is checked if you export the code before the contract in a specific network (mainnet or development chain).
best practices
To avoid similar problems in the future, make sure –
- Use export notifications in functions or other blocks that allow you to evaluate.
- Avoid ads to the console journal in imports or assessment of expressions.
- Consider using a separate module for the logic of your contract for organizing and maintaining.