Deploy Smart Contracts Ethereum

Beginner’s Guide: how to deploy smart contracts in the Ethereum blockchain

The Ethereum blockchain platform is still a relatively new technology, and it continues to evolve. Many helpful developers have created very important guides, however, a new developer may find the amount of information overwhelming! If you are a new Ethereum distributed app (DApp) developer, you need to code and deploy smart contracts. You are likely trying to find out how to deploy smart contracts, and in this guide, I will explain that.

However, let’s cover some basics first.

What is a smart contract?

Smart contracts have facilitated the widespread popularity of blockchain technology as we see today because they enable the creation of new business models. The Ethereum blockchain platform introduced smart contracts and many blockchain start-ups took advantage of this feature to launch innovative products.

Nick Szabo, a legal and cryptography expert had formulated the concept of smart contracts. These are pieces of code that employ “IF-THEN-ELSE” logic to transfer assets based on fulfillment of certain criteria.

Smart contracts have a few distinct features, as follows:

  1. They are open-source;
  2. Smart contracts are stored in a decentralized blockchain;
  3. They execute automatically;
  4. Once you deploy a smart contract, you can’t modify the code;
  5. The execution results of smart contracts are irreversible.

Ethereum DApps must run smart contracts as their backend code, hence you need to master smart contracts for Ethereum development. Read more about smart contracts in “Smart Contracts: The Ultimate Guide for the Beginners”.

The 4th and 5th distinguishing characters are very important when I explain how to deploy smart contracts. Since you can’t modify them after you deploy, and you can’t nullify their execution results, you must take adequate care in testing smart contracts. Hence, in this guide, I will first show you how to deploy smart contracts in a test blockchain network, and then how to do so in a production network.

How to deploy smart contracts in the Ropsten testnet

You need to diligently test your smart contracts because once you run them in your DApp, people will spend real Ether to use them. You don’t want your users to lose money due to bugs in your smart contacts!

Ropsten is a ‘testnet’. i.e. a test Ethereum blockchain network. There are different kinds of Ethereum testnets, i.e. lightweight, and heavyweight. Ropsten is a heavyweight testnet, however, you need to note that the security features in Ropsten aren’t stringent. This is because it’s a testnet, and the Ether you will use here are dummy Ethers, i.e. with no real value.

In this high-level guide, I will refer to a project that Merunas Grincalaitis, an Ethereum expert did and explained to the Ethereum developers’ community. Merunas described this project in his “Ultimate Guide to Convert a Web App To a Decentralized App Dapp” article. For code and commands, I will refer to his article as the “Reference article 1”.

Let’s dive in!

Install MetaMask

When you are just starting out as an Ethereum developer, you are likely not running a full Ethereum node. MetaMask is a great tool that helps you to communicate with the Ethereum blockchain even if you don’t run a full node.

This tool works as a web browser extension. Visit the MetaMask website and install the Chrome or Firefox extension. After you have installed it, notice the small icon at the top right corner of your browser. Click that, and set up a password after you accept their terms and conditions. You will also receive a 12-word private seed which you should secure carefully since you will need it in the future.

MetaMask sets up your connection to the Ethereum mainnet, i.e. the production blockchain network, by default. However, you will need to connect to the Ropsten testnet for testing your contracts, hence, click that MetaMask icon again.

When the small window opens, you will notice that the connection is for the “Main Network”. Click the drop-down menu, and change it to the ‘Ropsten Test Network’. Check out the reference article 1 for screenshots. Now that you have completed configuring your MetaMask, you will need to code smart contracts.

Use the Remix smart contract IDE to code and deploy your contracts

Remix” is an ‘Integrated Development Environment’ (IDE) for coding Ethereum smart contracts in Solidity, i.e. the proprietary language of Ethereum. It’s a DApp, hence you can access it over your web browser without installing any other tool.

Code your smart contracts using the Remix IDE and proceed to buy dummy Ether for deploying them in the Ropsten testnet. Remember that smart contract deployment requires you to pay the ‘Gas price’, so you need Ether. However, dummy Ethers are just fine for deployment in a testnet! Request 1 Ether from the MetaMask Faucet.

Now, a word about “Web3.js“. It’s a very helpful Ethereum JavaScript API library that enables you to communicate with a local or remote Ethereum node. At the time of MetaMask extension installation, your browser automatically received this API library. You need to use it, and for that, just ensure that your MetaMask connection to Ropsten is still open.

Come back to your Remix IDE window, and assuming you have coded your contact, see the top left corner of the Remix screen. You will notice a small “+” sign, with a label “Create”. Click that to deploy your contract into Ropsten, and return to MetaMask to confirm the transaction.

Consult the reference article 1 for screenshots. You have just learned how to deploy smart contracts into the Ropsten network!

How to deploy smart contracts in the Ethereum mainnet

Now, I will describe how to deploy smart contracts in the Ethereum main network. Alex Miller, a blockchain expert of considerable reputation, had published an article to explain a few important commands and configuration to new Ethereum developers. You can read it in “Getting Started as an Ethereum Web Developer“. I will refer to this for commands and configuration instructions in this high-level guide. Let’s then call it the “Reference article 2”.

To deploy your smart contracts into the Ethereum mainnet, you need to buy real Ether so that you can pay the “Gas price” and the miner-fees.

Create Ethereum account

If you don’t already have one, then you need to create an Ethereum account. There are two types of Ethereum accounts: contract accounts, and EOA accounts. Smart contracts are stored using contract accounts, hence these are entirely controlled by code.

Ethereum ‘Externally Owned Accounts’ (EOAs) are what Ethereum users own, and you need to create one such account. I recommend that you take the easiest route, which is to use the “eth-lightwallet“, i.e. a lightweight wallet that the reputed blockchain development company ConsenSys has built.

Set up your private key-public key pair, with the easy-to-use instructions they provide. Always secure your private key, never share it with anyone, and never upload it into any website or online forum! Buy some Ether and store it safely in your wallet.

Install Ethereum development tools

I recommend that you now install and configure a few important Ethereum development tools. You will need these not just for smart contract deployment, but also generally for Ethereum DApp development.

“testrpc”: This is a popular Ethereum client, and many DApp developers use it. It’s easy to use, and if you like ‘Command Line Interface’ (CLI), they have one. Install and configure using the testrpc GitHub instructions.

“Web3.js”: You have read about already earlier in this guide, however, in this exercise let’s install it using instructions in the Web3.js GitHub documentation. Remember that you need to configure the ‘aconfig.js’ file, which you can do by using their instructions.

“Truffle”: It’s an excellent tool to test your smart contracts in an automated and integrated manner, and to deploy them. You can organize your smart contracts into distinct projects by using their folder structure, which is another great advantage! Check out the Truffle GitHub instructions to install and configure it.

Truffle smart contract deployment

You now need to open “testrpc” and run an instance. You also need to access your private and public key information and update your “config.js” file with them. Check the reference article 2 for the detailed configuration instructions.

Assuming you have coded smart contracts and tested them, now you will deploy them into the Ethereum mainnet. Please ensure that your “testrpc” instance is still running and the connection is still live.

Now, navigate to your Truffle smart contract folder, and use the “truffle deploy” command. This completes your smart contract deployment, while you will need to pay the “Gas price” and miner-fees with Ether that you bought. Also, retain the contract address, since you will need to use it later when you run your DApp. Consult the reference article 2 for detailed commands.

To summarize this guide, I have explained how to deploy smart contracts into a testnet, as well as the Ethereum mainnet. I stress that when you are developing smart contracts, test, test, and test again before you deploy!

11 thoughts on “Beginner’s Guide: how to deploy smart contracts in the Ethereum blockchain”

  1. Spot on with this write-up, I honestly feel this
    amazing site needs a lot more attention. I’ll probably be returning to read more, thanks for the

  2. It’s perfect time to make some plans for the long run and it’s time to
    be happy. I have learn this publish and if I may just I want to recommend you few
    fascinating issues or suggestions. Maybe you can write subsequent
    articles relating to this article. I desire to learn more
    things approximately it!

  3. Wow, fantastic weblog structure! How lengthy have you ever been running a blog for?
    you make running a blog glance easy. The full look of your site is wonderful,
    as well as the content material!

  4. Wow, superb blog layout! How long have you been blogging for?
    you made blogging look easy. The overall look of your
    web site is magnificent, as well as the content!

  5. Great post. I was checking continuously this blog and I am impressed!

    Very useful info particularly the last part 🙂 I care for such info much.

    I was looking for this particular information for a long time.
    Thank you and good luck.

  6. Nice blog right here! Additionally your web site so much up very fast!

    What host are you using? Can I get your associate link for your host?
    I desire my website loaded up as quickly as
    yours lol

Leave a Comment

Your email address will not be published. Required fields are marked *