0

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;
    }
}

2 Answers 2

1

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 !!

0

I can't remember if this solved the console.log issue for me, but I know for sure it was helpful for resolving import warnings on a 'missing file'

I modified some solidity properties in .vscode/settings.json

{
  "solidity.defaultCompiler": "localNodeModule",
  "solidity.packageDefaultDependenciesContractsDirectory": "",
  "solidity.packageDefaultDependenciesDirectory": "node_modules"
}

Another weird thing about console.log for me is that it works locally with one arg, but not if I pass two.

Another recommendation I'd say for debugging is to connect to a Remix instance from your local IDE. I believe the console package is included in their application, so if the .vscode settings suggestion above doesn't work, using Remix should work.

1
  • 1
    Thanks Brother, 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 !! Jun 6, 2022 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.