【发布时间】:2022-10-15 01:15:51
【问题描述】:
console.log 不工作脚本/deploy.js和合同/WavePortal.sol在安全帽中。当我运行命令时npx 安全帽运行脚本/deploy.js它只显示 "" Compiled 1 Solidity file succeeded "" 。
它在我的 HardHat 环境中不起作用。甚至当我使用 INFURA 并使用命令运行时npx 安全帽运行脚本/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;
}
}
【问题讨论】:
标签: javascript solidity console.log ethers.js hardhat