0

I'm using Hardhat as my development framework, but there are a few beginner questions that I have about interacting with a deployed contract that I couldn't quite find in the hardhat docs (or if this involves Infura?).

  1. Can you control the owner address of the contract when deploying? How do you go about setting that? The address you want to use as the owner must be available on the network your deploying to? What about local development on the hardhat network?

  2. I've seen the docs about calling contract functions after you deploy using the hardhat console (instantiating a factory, await calls to a function, etc.), is this the "standard" way to call contract functions such as administrative onlyOwner functions like withdraw() or pause(), etc.? Is this approach acceptable for mainnet?

1 Answer 1

0
  • Can you control the owner address of the contract when deploying?

await ethers.getSigners();, returns an array of signers, by default when deploying if you're not specifying any signer. It uses index[0] of ethers.getSigners();

  • How do you go about setting that?

You can call functions using other signers (accounts / wallets): await yourContract.connect(signer[index]).yourFunction();

  • The address you want to use as the owner must be available on the network your deploying to?

All addresses across all EVM compatible chains (Ethereum Virtual Machine) so you can use for example your MetaMask to interact with any other EVM-compatible network using the same address (so same private key).

  • What about local development on the hardhat network?

theoretically, you can use the wallet you're using on your local to deploy on mainnet.

  • I've seen the docs about calling contract functions after you deploy using the hardhat console (instantiating a factory, await calls to a function, etc.), is this the "standard" way to call contract functions such as administrative onlyOwner functions like withdraw() or pause(), etc.? Is this approach acceptable for mainnet?

Hardhat is a development environment tool for compiling, deploying, testing, and debugging your Ethereum software. You can interact with your smart contract using the hardhat console, using scripts (e.g, web3.js ethers.js, etc), CLI, remix, metamask, etherscan, etc. There is no standard, for this.

You can deploy on testnet first to test, if it works on testnet it'll work on mainnet

3
  • Just out of curiosity, what is your personal preference when it comes to calling onlyOwner functions post-deploy? Or does that vary depending on the project? Commented Mar 22, 2022 at 13:25
  • you're not calling onlyOwner, you're calling a function that calls internally onlyOwner modifier It depends on you, and your preference. Remix is good for quick and custom testing, and the IDE is nice to start. For example, if you need to do this on regular basis like updating storage, I recommend you to do your calls through a script, otherwise, you can just use etherscan if it's a single transaction like transferOwnership, not sure If it answers your question
    – Adam Boudj
    Commented Mar 22, 2022 at 14:05
  • For testing I'll look into Remix, I find the hardhat console a tiny bit cumbersome. Maybe for some quick local development testing on the hardhat network I'll use the console, but for other testing Remix might be a good choice. As for mainnet, there are some one-time transactions I want to run, I'll look into Etherscan for that. Thanks Adam! Commented Mar 22, 2022 at 15:59

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.