When I run the following commands:
- Terminal 1:
npx hardhat node
- Terminal 2:
npx hardhat run scripts/sample-script.js --network localhost
I see the blockchain node created on terminal 1 execute things as I'd expect:
But if I run the following commands:
- Terminal 1:
npx hardhat node
(no changes) - Terminal 2:
node scripts/sample-script.js --network localhost
I see no activity on Terminal 1.
So what's the difference between node /* ... */
and npx hardhat run /* ... */
?
I'm running the standard sample-script.js (pasted below without its original comments):
const hre = require("hardhat");
async function main() {
const Greeter = await hre.ethers.getContractFactory("Greeter");
const greeter = await Greeter.deploy("Hello, Hardhat!");
await greeter.deployed();
console.log("Greeter deployed to:", greeter.address);
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});