console.log在scripts/deploy.js和smart_contract中不工作 &



console.log不工作scripts/deploy.js合同/WavePortal.sol在建筑工人。当我运行命令npx hardhat运行scripts/deploy.js它只显示"编译1个Solidity文件成功".
它不能在我的HardHat环境中工作。甚至当我使用INFURA并使用命令npx hardhat run scripts/deploy.js——network ropsten时也没有我搜索了从youtube到StackOverflow的所有地方,但没有找到任何解决方案。我只得到一个提示——>

由于合约代码在链上运行,您将从链输出中看到console.log,而不是在javascript控制台输出中。但是我不能得到这个表述....请帮帮我

脚本/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
};

合同/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;
}
}

在remix中进行了快速测试,似乎您的智能合约工作正常,并打印出了行。

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!

你的deploy.js看起来也很好。可能是与代码无关的设置问题。

经过一番努力,我终于找到了解决办法。实际上我已经安装了vs code扩展Hardhat+Solidity提供的建筑工人正式。所以,我卸载了它,我通过Juan Blanco安装了Solidity扩展,并将其版本降级为v0.0.135,现在它的工作绝对很好!!

最新更新