Javascript required
Skip to content Skip to sidebar Skip to footer

Can Remix Be Used to Upload Contract to Ropsten

A Smart Contract is a reckoner programme that directly and automatically controls the transfer of digital assets between the parties under certain conditions. A smart contract works in the same way as a traditional contract while besides automatically enforcing the contract. Smart contracts are programs that execute exactly as they are gear up up(coded, programmed) past their creators. Just similar a traditional contract is enforceable by law, smart contracts are enforceable by code.

Upwards to this betoken, we have our smart contracts written and compiled without any errors. Let'due south see how we can deploy our smart contract on rinkeby test network. Deploying a contract on the principal blockchain costs money (in the grade of cryptocurrency), so nosotros have test networks to develop and exam our smart contracts. In the test network, fake ethers are added to our wallet to facilitate transactions. One such network provided by Ethereum is Rinkeby.

Installing MetaMask

MetaMask provides browser support to communicate with blockchain networks. We tin add together an business relationship, get ethers to our account or send transactions to some other account. It is like a wallet from where we can spend our cryptocurrency. To install metamask,

  1. Go to https://metamask.io/
  2. Download it to your browser.

On starting for the first time, to fix your wallet MetaMask gives you a seed phrase of 12 words. This phrase is unique and can be used to restore your account, in instance you lot forgot your password.

Getting Test Ethers

Deploying contracts on the test network requires some exam ethers, which, plainly does not have any existent value. In the blockchain, every interaction with a contract costs some fees(gas) and the interaction is known equally a transaction. Since deploying our contract on rinkeby is also a transaction, nosotros demand some test ethers to facilitate the transaction. To get examination ethers we will be using a Faucet. Go to https://faucet.metamask.io/ and do the simple job asked to get some free test ethers.

Creating Infura Endpoint

We demand an API through which we can access the rinkeby network. Infura makes information technology quite easier to access the test/main network and deploy our contract on them. Create an infura endpoint on the rinkeby network.

  • Go to infura.io and sign up for an account if yous don't take one.
  • Click on Ethereum on the left panel.
  • Write your project proper noun and click to create the projection.
  • This should create an endpoint for your projection and information technology should await somewhat like to below.

Now we need an npm bundle HDWalletProvider, this signs our transaction and makes the deployment process a less pain.

npm install @truffle/hdwallet-provider        

Configuring truffle-config.js And Deploying To Rinkeby

Now we have, our truffle hdWallet-provider in our node modules, an endpoint from infura account, and the seed-phrase which we have used during MetaMask installation.

Let's configure our truffle-config.js. Open up truffle-config.js and import truffle hdWallet provider at the top.

const HDWalletProvider = require('truffle-hdwallet-provider');        

To configure the network, we will edit the network section of truffle-config.js. This should look somewhat similar this.

const HDWalletProvider = require('truffle-hdwallet-provider');    // Useful for deploying to a public network.     // NB: It's important to wrap the provider as a function.     // ropsten: {       // provider: () => new HDWalletProvider(mnemonic, `https://ropsten.infura.io/v3/YOUR-Project-ID`),       // network_id: 3,       // Ropsten'due south id       // gas: 5500000,        // Ropsten has a lower block limit than mainnet       // confirmations: ii,    // # of confs to look betwixt deployments. (default: 0)       // timeoutBlocks: 200,  // # of blocks earlier a deployment times out  (minimum/default: fifty)       // skipDryRun: true     // Skip dry run before migrations? (default: false for public nets )     // },        
  • Replace ropsten with rinkeby.
  • Mnemonic with seed-phrase (obtained from MetaMask).
  • https://ropsten.infura.io/v3/YOUR-Project-ID with the infura endpoint you created for your projection.
  • network_id:four,

After doing these changes your section should wait something like this.

          rinkeby: {        provider: () => new HDWalletProvider(`YOUR_SEED_PHRASE`, `https://rinkeby.infura.io/v3/b63bffeec2e545f2a3e9b3e9423d6180`),        network_id: four,       // Ropsten's id        gas: 5500000,        // Ropsten has a lower block limit than mainnet        confirmations: ii,    // # of confs to wait between deployments. (default: 0)        timeoutBlocks: 200,  // # of blocks before a deployment times out  (minimum/default: 50)        skipDryRun: true     // Skip dry run before migrations? (default: false for public nets )      },        

Save the file and then open the truffle console and then drift on the rinkeby network.

truffle migrate --network rinkeby        

That'south all done. Once your contract is deployed on rinkeby, you can cheque the transaction detail on etherscan.  Become to the link and copy and paste your deployed contract address to get the details about your transaction.

Notation:

  1. To deploy on the main network, get infura endpoint for the main network, and configure the config file.
  2. Replace rinkeby with main, and network id with 1.
  3. So truffle migrate –network main.

babbagephompecture.blogspot.com

Source: https://www.geeksforgeeks.org/deploying-smart-contract-on-test-main-network-using-truffle/