console.log not working in scripts/deploy.js and contracts/WavePortal.sol in Hardhat. When I run the command npx hardhat run scripts/deploy.js it only shows "" Compiled 1 Solidity file successfully "" .
Its not working in my HardHat environment. Not even when I am using INFURA and running with the command npx hardhat run scripts/deploy.js --network ropsten
I searched everywhere from youtube to StackOverflow but didn't got any solution. I only got one hint --->
Since the contract code is running onchain, you'll see the console.log from the chain output, not in your javascript console output. But I am not able to get this.... Please help me
scripts/deploy.js
const [owner, randomPerson] = await hre.ethers.getSigners();
const waveContractFactory = await hre.ethers.getContractFactory("WavePortal");
const waveContract = await waveContractFactory.deploy();
await waveContract.deployed();
console.log("Contract deployed to:", waveContract.address);
console.log("Contract deployed by:", owner.address);
let wavecount;
wavecount = await waveContract.getTotalWaves();
let waveTxn = await waveContract.wave();
await waveTxn.wait();
wavecount = await waveContract.getTotalWaves();
};
const runMain = async () => {
try {
await main();
process.exit(0); // exit Node process without error
} catch (error) {
console.log(error);
process.exit(1); // exit Node process while indicating 'Uncaught Fatal Exception' error
}
// Read more about Node exit ('process.exit(num)') status codes here: https://stackoverflow.com/a/47163396/7974948
};
contracts/WavePortal.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import "hardhat/console.sol";
contract WavePortal {
uint256 totalWaves;
constructor() {
console.log("Yo yo, I am a contract and I am smart");
}
function wave() public {
totalWaves += 1;
console.log("%s has waved!", msg.sender);
}
function getTotalWaves() public view returns (uint256) {
console.log("We have %d total waves!", totalWaves);
return totalWaves;
}
}
Did this with a quick test in remix, seems like your smart contract is working fine and prints out the lines.
console.log:
Yo yo, I am a contract and I am smart
[vm]from: 0x5B3...eddC4to: WavePortal.(constructor)value: 0 weidata: 0x608...17274logs: 0hash: 0x1d0...16b87
transact to WavePortal.wave pending ...
console.log:
0x5B38Da6a701c568545dCfcB03FcB875f56beddC4 has waved!
[vm]from: 0x5B3...eddC4to: WavePortal.wave() 0xd91...39138value: 0 weidata: 0x6fe...15b44logs: 0hash: 0xbda...02370
call to WavePortal.getTotalWaves
console.log:
We have 1 total waves!
Your deploy.js looks fine as well. Could be a setting issue apart from code.
After trying so hard I got the solution. Actually I've installed vs code extension Hardhat+Solidity provided by Hardhat officially. So, I uninstalled it and I installed Solidity extension by Juan Blanco and I downgraded its version to v0.0.135 and now its working absolutely fine !!