3

I executed some contract creation scripts by terminal through hardhat, "npx hardhat run...." what I noticed is balances of hardhat accounts are not reduced. Meaning as there is no gas spent for contract creation. Then I connected to hardhat node through remix and executed simple contract creation and balance reduced. My original script creates proxy contracts and that is the only thing I can see as different. I double checked in script is the chainId same on both terminal script and remix and both are 1337. Run out of ideas.


Problem is seems that command npx hardhat --network hardhat run /somescript.js not working, even if you have local hardhat network defined in hardhat.config what is working is npx hardhat --network localhost run /somescript.js . Assuming you have like me, running hardhat node locally

    //in hardhat.config
    require("@nomicfoundation/hardhat-toolbox");
    require("@openzeppelin/hardhat-upgrades");

     module.exports = {
       defaultNetwork: "hardhat",
       networks: {
          hardhat: {
            chainId: 1337,
          },


//deploy.js
const Destroyer = await ethers.getContractFactory("Destroyer", {
    signer: admin,
  });
  const destroyer = await upgrades.deployProxy(Destroyer, [exchange.address], {
    kind: "uups",
  });
  await destroyer.deployed();

  console.log("Destroyer: " + destroyer.address);
7
  • Can you post your deployment script (js)?
    – immaxkent
    Dec 8, 2022 at 12:24
  • script snippet is added to post above. What is wondering still is where code actually executed with npx hardhat --network hardhat run /somescript.js
    – Josip
    Dec 9, 2022 at 9:21
  • Sorry, could you rephrase that? 'what is wondering still is where code actually executed'
    – immaxkent
    Dec 9, 2022 at 11:24
  • you started off by saying that the balances were unchanged after deployment on localhost, but in your second post you are saying that the hardhat deployment isnt working in the terminal. Which is it??
    – immaxkent
    Dec 9, 2022 at 23:48
  • If I go execute the script with npx hardhat --network localhost run /somescript.js with running npx hardhat node I see in terminal logs (trasactions). When I do the same withnpx hardhat --network hardhat run /somescript.js I do not see transactions executed in terminal. My expectation is that both commands should do the same and run script on hardhat blockchain node on localhost as "hardhat" network is actually localhost. What I was wondering is, if with npx hardhat --network hardhat run /somescript.js I do not see transactions, where this script is running as I did not get any errors?
    – Josip
    Dec 10, 2022 at 12:23

1 Answer 1

0

If I understand you correctly, your third comment in the thread errs toward the problem: you have no blockchain running.

The execution of npx hardhat --network hardhat run /somescript.js defined the network under the --network flag as hardhat, which isn't a network - simply a dev environment - you need to define a chain here (e.g. localhost, which would be a hardhat node, i.e. is why your other script created logged transactions, or goerli, mainnet etc.)

2
  • so you are saying that --network hardhat is used mostly for running unit tests. environment creates temporary blockchain behind the scenes, executes tests and terminates blockchain node process.
    – Josip
    Dec 20, 2022 at 10:52
  • Kinda yeah: hardhat is, and I quote: * Hardhat is a development environment that helps developers in testing, compiling, deploying, and debugging dApps on the Ethereum blockchain*. So, you can use it to connect to specified networks (be it localhost or a testnet or whatever) in developing you dApps
    – immaxkent
    Dec 23, 2022 at 10:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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