So I have followed multiple tutorials on getting started with smart contract development in Ethereum and have read many, many pages on security and development in OpenZeppelin. How exactly do I go about actually deploying my project to the Ethereum mainnet using Hardhat though? I can only find info on deploying to test networks!
How do I deploy to Ethereum mainnet from Hardhat?
Expand the networks
section of the config file.
Example configuration:
mainnet: {
url: "https://mainnet.infura.io/v3/<your_infura_key>", // or any other JSON-RPC provider
accounts: [<your_private_key>]
}
Instead of specifying the private key directly, you can also specify the mnemonic
phrase.
For more details, see the docs.
How trustworthy does the JSON-RPC provider need to be? –
Fore
Is there no way for Hardhat to send the transaction to the blockchain directly? –
Fore
@LukeHutchison You don't need to trust the provider, as the transaction is signed in your app (using the private key) and the actual private key is never sent to the provider (assuming that you trust/verify Hardhat and all other dependencies that they don't send the private key elsewhere)... This is the most direct way of sending a transaction, as it needs to be broadcasted from one of the nodes of the P2P (Ethereum) network to the rest of the network. If you're not willing/able to rely on a third-party node, you can also run your own node. –
Fichte
In the context of hardhat, mainnet, testnet or any other network work in the same way. These are just the tags. you can define multiple networks in hardhat config
module.exports = {
solidity: "0.8.9",
defaultNetwork: "hardhat",
networks: {
hardhat: {},
rinkeby: {
url: RAPI_URL,
accounts: [RINKEBY_WALLET_ADDRESS_PRIVATE_KEY]
},
mainnet: {
url: ETH_MAINNET_RPC_URL,
accounts: [MAINNET_WALLET_ADDRESS_PRIVATE_KEY]
},
},
}
then for deploy use the command like this
npx hardhat run scripts/deploy.js --network rinkeby
or
npx hardhat run scripts/deploy.js --network mainnet
© 2022 - 2024 — McMap. All rights reserved.