Reader small image

You're reading from  Mastering Blockchain Programming with Solidity

Product typeBook
Published inAug 2019
Reading LevelIntermediate
PublisherPackt
ISBN-139781839218262
Edition1st Edition
Languages
Concepts
Right arrow
Author (1)
Jitendra Chittoda
Jitendra Chittoda
author image
Jitendra Chittoda

Jitendra Chittoda is a blockchain security engineer at ChainSecurity. His day job is to perform security audit on smart contracts and expose security vulnerabilities in Solidity and Scilla contracts. He has also developed a non-custodial, decentralized, P2P lending contracts for ETHLend. The Solidity contracts that he has developed or audited handle over $100 million worth of cryptoassets. He also served as a tech and security advisor in various ICO projects. Before finding his passion for blockchain, he coded in Java for over 11 years. He is the founder and leader of Delhi-NCR-JUG, a non-profit meetup group for Java. He holds a master's degree in computer applications and is regularly invited as a speaker at various conferences and meetups.
Read more about Jitendra Chittoda

Right arrow

Learning MetaMask and Remix

In previous chapters, we learned about blockchain and what a smart contract is. A smart contract should be used only when it is required to use the programmable properties of the blockchain. We looked into the most famous contract-oriented language, Solidity. We also understood the basic syntax of the language and how to write smart contracts in Solidity. As we have learned the language, we now need to learn about some tools that are useful for developing Solidity contracts.

In this chapter, we will look at tools that are used to create, test, and deploy contracts. We will look at how to set up MetaMask and the Remix IDE and how to use them.

The following topics will be covered in this chapter:

  • Setting up the MetaMask browser plugin
  • Understanding transfers, networks, and accounts on the MetaMask plugin
  • Using the Remix IDE for contract development
  • Testing...

Technical requirements

In this chapter, we are going to look into MetaMask and the Remix IDE for Solidity contract development. To install and configure those tools, you first need to satisfy their technical requirements:

  • Latest version of npm and Node.js.
  • MetaMask: MetaMask is an open source, internet browser plugin that you can install from https://metamask.io/. This is officially supported for Google Chrome, Firefox, Opera, and Brave internet browsers. There are no additional requirements for working with MetaMask. The MetaMask source code can be found on GitHub at https://github.com/MetaMask/metamask-extension.
  • Online Remix IDE: The Remix IDE is an online version of the Solidity editor and Integrated Development Environment (IDE). You can access the IDE by opening the https://remix.ethereum.org in your internet browser.
  • remixd: remixd is an open source, command-line...

Using the MetaMask plugin

MetaMask is a plugin for internet browsers, which lets you connect to the Ethereum blockchain. You can connect and interact with distributed applications using MetaMask without installing a local full blockchain node. It provides the UI to sign the transactions and keep your identities for different distributed applications.

You can connect to the Ethereum blockchain by installing the Ethereum wallet software provided by the Ethereum Foundation itself. However, it requires the full Ethereum blockchain to be downloaded to your machine before initiating any transaction. Downloading the full blockchain ledger would require gigabytes (GBs) of hard-drive storage space and necessitates keeping the wallet software running all of the time. Hence, it is preferred to use the MetaMask plugin, which is fast, provides secure communication, and needs a negligible...

Using the Remix Solidity IDE

To write Solidity contracts, the Ethereum Foundation has provided an online version of the Solidity IDE. You can open the Remix IDE in your internet browser by going to https://remix.ethereum.org. This online tool has the basic features required to write Solidity contracts and compile, test, and deploy your contracts.

Ethereum Foundation is responsible to take decisions for the future development of the Ethereum blockchain.

As it's an online version, it is always updated with the latest features and compilers. You don't need to do any updates if you are using the online version. Let's learn how to use the Remix IDE.

The Remix IDE overview

Once you download and open the Remix...

Using the blockchain explorer at etherscan.io

You can see the status of the transaction, and the state of the wallet and contract accounts on etherscan.io (the Ethereum block explorer). As we have deployed the DeploymentExample contract in this chapter, we can see the status of the contract by opening https://rinkeby.etherscan.io and searching for the contract address.

As shown in the following screenshot, the status of the contract on etherscan is that it has a balance of 0.8 ether. The contract code is also published for this contract; you can see the contract code by opening the Code tab.

During the transaction, different events the contract has triggered can be seen also under the Events tab:

The contract status on the block explorer, etherscan.io

Using etherscan, you can also access all of the public view functions and public state variables. To access these, open...

Ethereum wallet software

You can download Ethereum wallet software and access your wallet account and deploy contract accounts. However, to perform these operations, you would have to download the blockchain. This makes Ethereum wallet software less developer-friendly. On the other hand, the MetaMask, Remix, Truffle, and Ganache tools provide fast and developer-friendly environments. Hence, Ethereum wallet is not used mostly by the developers.

There might be some special requirements when you are deploying your own private Ethereum network; in that case, Ethereum wallet should be used.

We are not covering Ethereum wallet's features in this book. The reader can download and play with it to understand its features and limitations. You can download Ethereum wallet software Mist from https://github.com/ethereum/mist/releases.

Parity also provides some Ethereum software called...

Using myetherwallet.com

There is a website called https://www.myetherwallet.com/, which also provides tools to access the Ethereum blockchain and initiate some special transactions:

The myetherwallet.com website provides tools for Ethereum

As shown in the preceding screenshot, using this, you can perform the following operations:

  • Create a new Ethereum paper wallet. When the private key is printed on paper and kept secret this is called a paper wallet.
  • Connect using different hardware wallets and different wallet formats and initiate the transactions.
  • Just like the Remix IDE can access contract functions, in the same way, you can also access these functions via myetherwallet.com using the ABI of the contract only.
  • Using Send Offline, you can sign the Ethereum transaction from an offline (air gapped) computer to improve security.
  • Using Ethereum Name Service (ENS), you can register...

Summary

We learned about MetaMask and the Remix IDE in this chapter. As of the time of writing, MetaMask is the easiest and most user-friendly way to access Decentralized Applications (DApps). It is also developer-friendly for building Ethereum contracts and interacting with the Remix IDE.

The Remix IDE provides a great way for developers to deploy and access contracts. It was the only way for the developers to do so before the Truffle framework was developed. However, after using the Truffle framework, developers may use Remix IDE to access already-deployed contracts and call functions.

It is difficult to test and debug contracts on the Remix IDE. The Truffle framework provides tools for this, which we will look into in the next chapter.

Questions

  1. How many accounts can I create on MetaMask?
  2. Can I connect MetaMask to my own private blockchain?
  3. What is the MetaMask secret seed and when would it be used?
  4. Can MetaMask receive ERC20 tokens?
  5. Can I cancel a pending transaction using MetaMask?
  6. How can I access the JSON ABI for the contract using the Remix IDE?
  7. Should I always use optimization for contracts?
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Mastering Blockchain Programming with Solidity
Published in: Aug 2019Publisher: PacktISBN-13: 9781839218262
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Jitendra Chittoda

Jitendra Chittoda is a blockchain security engineer at ChainSecurity. His day job is to perform security audit on smart contracts and expose security vulnerabilities in Solidity and Scilla contracts. He has also developed a non-custodial, decentralized, P2P lending contracts for ETHLend. The Solidity contracts that he has developed or audited handle over $100 million worth of cryptoassets. He also served as a tech and security advisor in various ICO projects. Before finding his passion for blockchain, he coded in Java for over 11 years. He is the founder and leader of Delhi-NCR-JUG, a non-profit meetup group for Java. He holds a master's degree in computer applications and is regularly invited as a speaker at various conferences and meetups.
Read more about Jitendra Chittoda