How to deploy hardhat contract to mainnet without ALCHEMY or INFURA ?
Alchemy, Infura, and others, are services offering connection to nodes of the Ethereum network.
Contract deployment means that you broadcast a transaction with specific parameters (data field containing the compiled bytecode, to field empty). But you can only broadcast a transaction to the rest of the network from a node connected to the network.
So apart from using a third-party service, you can also run your own node. For example using the go-ethereum client software.
Then you'll be able to broadcast the transaction through this your own node, instead of a third-party one.
Related
Can I deploy ERC-20 token on Aurora and bridge it to ETH Mainnet ERC-20 contract?
We plan to launch our token as Aurora native ERC-20, but we’ll need to bridge it to Ethereum and NEAR Protocol. Would it be possible to include the token in the list of supported Rainbow Bridge tokens? What are the steps on how to do this properly via the Rainbow Bridge?
At the moment bridging of Aurora native tokens to Ethereum is not possible, but eventually this functionality is to be added.
However, being ERC-20, the token should originate from Ethereum and then be represented on Aurora.
To add it to Aurora, you’ll need to deploy it and create a PR in https://github.com/aurora-is-near/bridge-assets.
On spinning up a hardhat node locally, I get 10 addresses pre funded with 10k ETH. But none of these show up on metamask when I connect it to localhost:8545. As a result I'm not able to interact with a dapp deployed locally
Am I doing something wrong?
Usually, the back-end development project provides funded accounts which you can enter into Metamask, It's not like the Goerli or (now defunct) Rinkeby test networks where you can visit a site and have some ETH added to your test account because those test networks are hosted. You need to spin up a local project and have it provide funded accounts.
Such an example is Lesson 9: Hardhat Smart Contract Lottery in (Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript by Free Code Camp)
here is the code ...
https://github.com/PatrickAlphaC/hardhat-smartcontract-lottery-fcc
If you run that project it generates a number of addresses which you can connect to in Metamask.
MetaMask has no way of knowing which of your local accounts you want to import, or which are funded (prior to the import).
So you need to import the accounts to MetaMask manually using the private keys provided by Hardhat.
I understand both methods are used for running dapps. What I don't understand is the clear cut difference between the two or how one is more advantageous over the other? I'm new to blockchain, so please explain with a simple terminology.
The difference is:
Infura has geth installation running for you, exposing most used, most low-CPU-consuming methods for you via Web.
You can install geth yourself but you will need a server with about 500GB of SSD disk, and wait 1 month to download the entire State.
If you are not going to do any serious monetary transfers I recommend using Etherscan, it is more complete than Infura.
To execute transactions and/or queries against blockchains, you need connections.
Infura is an API gateway to main network and some test networks. It supports a subset of web3 interface. When you like to execute a transaction against the Ethereum blockchain, you may use infura as connection to the blockchain. So in this case, you are not directly connected to Ethereum, but infura has a connection. The Metamask Browser Plugin works with infura.
The alternative approach is to have an Ethereum client like geth or parity running on your machine. In this case, the Ethereum Client connects to several public nodes of the blockchain and forwards your transactions to the blockchain.
Depending on your architecture and requirements, both approaches could be the best solution.
I began to understand how to develop smart contracts on the Ethereum blockchain and how to write a web-script for interacting with a smart contract (buying, selling, statistics ...) And I came to the conclusion what to do. I wanted to know if I understood everything correctly.
We write the contract on http://remix.ethereum.org, check whether
all functions work correctly.
We are raising TRUFFLE + GANACHE to test a contract on our own
private blockchain.
We write a simple front-end to interact with the contract, we will
do everything through Metamask.
Deploy everything into the Ropsten Ethereum test network and test
everything there.
After successful testing in the test network, we fill everything
into the main blockchain of Ethereum.
Did I understand everything correctly, and did I take the right steps?
The steps you outlined look good. I would actually say that you don't need to do the first step, as you can use truffle during all steps of the development process.
Create a new Truffle project (truffle init) and write the smart contracts and migration scripts.
Write thorough unit tests using JavaScript (and/or Solidity) and run these tests on a local Ganache instance (truffle test). My library truffle-assertions can be used to assist in writing these unit tests.
Write a frontend to the contract which uses the artefacts generated by Truffle (truffle compile and truffle migrate). This frontend can be manually tested in the browser with Metamask.
Add connection configuration to the truffle.js file to connect with Ethereum Testnets (Rinkeby, Kovan, Ropsten) and Mainnet through truffle-hdwallet-provider and Infura, so the contracts can be deployed to these networks. Further explanation.
Deploy to a testnet of choice (truffle migrate --network ropsten) and do more testing as in step 3.
After you've thoroughly tested all functionality across the multiple development steps, deploy to the mainnet (truffle migrate --network mainnet).
Of course most of these steps can still be completed without Truffle, but Truffle really simplifies a big part of the process, and there is a lot of documentation/resources available for it.
I don't understand where actually the smart contract goes, when I click on create under remix.ethereum.org. If I choose for example the Injected Web3, this should publish the contract to the ropsten test net, right? But how can I access the contract then? When I use metamask it injects me the right provider when I use web3.js, but how can I find this contract now, if I don't want to use the injected web3, but manually choose the provider address in web3.js? Can I access the smart contract this way?
Edit: I don't know what should be wrong about my question.I seriously find nothing about how how to connect to a smart contract for example in the ropsten test network without injected web3. Normally you do this in web3.js:
if (typeof web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
} else {
// set the provider you want from Web3.providers
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}
}
But if you don't have an injected web3, then you use the localhost. But I cannot connect then to the smart contract, because it does not know, in which net I actually published the smart contract, right?
Remix has 3 different environment options that can be used to deploy/test Solidity contracts: JavaScript VM, Injected Web3, and Web3 Provider. This option can be changed under the Environment drop down under the Run tab. (It looks like you've got this part...just documenting for completeness).
JavaScript VM: This is Remix's own internal sandbox. It does not connect to MainNet, TestNet, or any private network. It's an in-memory blockchain that can be used for simple testing and quick mining.
Injected Web3: This is the option to use for the browser plugin (MetaMask). Here, you are telling Remix to defer all control of the blockchain integration to the MetaMask plugin. At this point, MetaMask controls which network you are connecting to. In the plugin, you can connect to MainNet, Ropsten, Rinkeby, etc through Infura's node network. In this case, you're not running a node locally. MetaMask also has a localhost option where you can run your own node locally and MetaMask will send all transactions to it (this local network can be a private network using any node client or you can use a test blockchain like TestRPC).
Web3 Provider: This allows you to enter a URL in Remix to connect to the blockchain. The most common setup here is to be running a local node and connecting to it through it's IP/port. This is pretty much the same as using MetaMask's localhost option, but you're just cutting the plugin out of being the middleman. Just like option #2, the network your connected to depends on how you've configured your local node (it can be main, test, private, etc.).
So, "where your smart contract goes" depends on which of the configurations you have set up. Selecting Injected Web3 does not automatically mean your contract is being deployed to Ropsten. It depends on which network you have selected in the MetaMask plugin.
When using MetaMask through Remix, you need to use the plugin to select the appropriate account and confirm/reject transactions. Selecting the account is a bit confusing because Remix doesn't pick up all of the accounts imported into MetaMask. The Account dropdown will only have the account currently selected in MetaMask. In addition, if you change the account in MetaMask, you have to reload Remix for it to have that account selected in the dropdown. It does NOT automatically detect when the account has changed in MetaMask.
Once the account is properly selected (and assuming you're using an account that holds ether), you can now deploy your contract. Hit Create in Remix and then switch over to the plugin again. There, you should see a pending transaction waiting to approved. Select the transaction, then click Submit.
Transaction list:
Approve/Reject screen:
After submitting, it'll take a few seconds for the transaction to be mined. MetaMask will show when it's completed. That's it! To interact with the contract, you can initiate your transactions through Remix similar to the deployment steps above.