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!
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.
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
Related
I have installed the latest version of hardhat. It installed fine.
After setting hardhat up and installing all the required packages, when I run:
npx hardhat accounts
It gives an error:
Error HH303: Unrecognized task accounts
It seems like 'account' task has been removed in the latest version of hardhat. My question is now to get the list of wallet accounts that hardhat generates?
I have the same situation on 2022-08-16.
To get the available accounts, I use the npx hardhat node command.
The command sequence I performed was:
$ npx hardhat --version
2.10.1
$ npx hardhat accounts
Error HH303: Unrecognized task accounts
For more info go to https://hardhat.org/HH303 or run Hardhat with --show-stack-traces
$ npx hardhat node
Started HTTP and WebSocket JSON-RPC server at http://127.0.0.1:8545/
Accounts
========
WARNING: These accounts, and their private keys, are publicly known.
Any funds sent to them on Mainnet or any other live network WILL BE LOST.
Account #0: 0xf39Fd6e51a...ffFb92266 (10000 ETH)
Private Key: 0xac0974bec39a1...478cbed5efcae784d7bf4f2ff80
Account #1: 0x70997970C51812...b50e0d17dc79C8 (10000 ETH)
Private Key: 0x59c6995e998f97a5a...9dc9e86dae88c7a8412f4603b6b78690d
.
.
.
This is because the accounts tasks is not included in the latest release. Add the following in your hardhat.config.js
task("accounts", "Prints the list of accounts", async () => {
const accounts = await ethers.getSigners();
for (const account of accounts) {
console.log(account.address);
}
});
im not sure but I managed to fix this by migrating waffle to Beth chai masters as required and rm from config the waffle and add the chai masters
after that could not get accounts els how than "npx hardhat node" looks like accounts are displayed when launching the node if it can help!
I use yarn hardhat node to display a list of hardhat accounts on the terminal
I've successfully deployed my SmartContracts locally to Ganache and want to now take it to the next level by testing them on ROPSTEN.
For some reason, even though I've done this a million times before with other projects, when I run
truffle migrate --network ropsten
I'm not getting any sort of results, which is to say I'm not getting errors, but its also just not succeeding. It just says:
Compiled successfully using:
- solc: 0.5.8+commit.23d335f2.Emscripten.clang
...and puts me back at the prompt line, waiting for my next command.
My DEV ENVIRONMENT is:
Operating System: Mac OS Catalina v.10.15.1
Truffle Version (truffle version): v.5.0.34
Node Version (node --version): v.10.16.3
NPM Version (npm --version): v.6.14.4
├─┬ #truffle/hdwallet-provider#1.0.35
│ └── web3#1.2.1
├─┬ truffle-hdwallet-provider#1.0.17
│ └── web3#1.2.1
└── web3#0.20.7
(Yes, I seem to have two versions of Web3 - but I don't think that's the problem...)
My truffle-config.js file looks like this:
require('dotenv').config();
const HDWalletProvider = require('truffle-hdwallet-provider');
module.exports = {
ropsten: {
provider: function () {
return new HDWalletProvider(
process.env.GANACHE_MNENOMIC,
"https://ropsten.infura.io/${process.env.INFURA_API_KEY}"
)
},
network_id: 3,
from: "0xB4xxxxxxxxxxxxxxxxxxxxxxx",
gas: 8000000,
gasPrice: 20000000000,
confirmations: 2, // # of confs to wait between deployments. (default: 0)
skipDryRun: true
},
My .env file has the MNEMONICs and the INFURA_API_KEY which are all valid.
Any ideas what might be going on here?
You need a faucet and get some funds on your ropsten address so that migration of contract is executed.
I have just started learning blockchain development
I have created an ethereum sidechain, which is running on docker containers in my local machine.
I have previously used solidity to write smart contracts and deploy them on the testnet using truffle, or by getting the provider from infura.
Note: wherein each container acts as a node.
But how do I do the same thing for my private chain?
You need to configure truffle to point to your testnet. The truffle config docs describe how to do this in detail. Essentially you want to put the following in your truffle.js file:
networks: {
test: {
host: "<ip address of one of your docker containers>",
port: <port number your container is listening on>,
network_id: "*" // match any network id
}
}
I cannot access a deployed and mined Ethereum contract on a private network from the Geth Javascript console. Not sure where the issue is, any help is appreciated.
Thank you in advance for your time.
Scenario
I launched my Geth as below
geth --datadir ~/.ethereum/myProject --networkid 1234 --rpc --rpcport 8546 --rpcapi "eth,net,web3" --unlock 0 console
I've deployed and mined an Ethereum contract (to simplify things, I've used the default MetaCoin contract provided by Truffle), and I got the trx and contract address back.
I can access it from the Truffle console but if I try from the Geth Javascript console I get an error.
Please refer to the pictures below:
Truffle console
Geth javascript console
Software used
Geth (v1.7.3-stable)
NodeJS (v6.12.3)
TestRPC (v6.0.3 (ganache-core:2.0.2))
Truffle (v4.0.5)
Geth does not know about MetaCoin. In Geth console, you need to do:
var MetaCoin = web3.eth.Contract(metaCoinJsonAbi, itsAddress);
// or web3.eth.contract depending on the version of Web3
Then you can use it. Refer to this.
I'm working on a project that uses truffle framework and want to test my code on a private ethereum network. When I run truffle console, it connects to the network specified in truffle.js, like this:
module.exports = {
networks: {
development: {
host: "localhost",
port: 8545,
network_id: "*" // Match any network id
}
}
};
Is there a syntax that I can use to point truffle to a geth.ipc file somewhere on the system, or is truffle limited to network endpoints?
By definition, the endpoint is a RPC listener, not a file.
You can use geth to create a testnet.
To use it, you need to use it as an endpoint.
See the configuration options of geth to specify the port if it's not connecting right away.
testrpc is also allowing you to create a testnetwork (8535 is the default port).