0

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: enter image description here

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

1 Answer 1

1

npx hardhat node and npx hardhat run are both tasks that come by default in hardhat. You can check all defined tasks with the following commands: npx hardhat or npx hardhat help.

enter image description here

Here you have that:

  • node: Starts a JSON-RPC server on top of Hardhat EVM;
  • run: Runs a user-defined script after compiling the project

You can also create your own tasks. Take a look at the docs.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.