POSTED 2 months ago

Ethereum 101 - Part IV - Developer Tools

Part IV - Developer Tools

Developer Environment

This section includes a brief showcase of the various integrated development environments in the Ethereum ecosystem. Despite being frontier technology, there is a strong developer contingent and a diverse set of open source tools available that aid in the development and deployment of secure smart contracts.

There are several development environments and frameworks available to Ethereum developers. This documentation will highlight the more popular and widely known frameworks. Starting out, Remix and MetaMask would serve as a good springboard into decentralized app development.

Remix on top of Geth / Mist

Returning to the Geth / Mist development environment that we bootstrapped at the beginning of this documentation, let’s walk through the process of debugging a simple contract using Remix (browser solidity).

In the Mist Ethereum Wallet, click on the ‘Develop / Open Remix IDE’ button to open up an instance of Remix. Typically, if this is the first time running Remix, then the ‘Ballot.sol’ contract should be automatically loaded. To ensure our Remix browser is connected to Mist, access the ‘Run’ tab, and confirm that ‘Injected Web3’ is found in the Environment section. Secondly, ensure that the accounts you created using ‘personal.newAccount()’ in your geth node are present in the ‘Account’ field just one field below. From here you can input your smart contract into Remix for deployment and debugging.

Screenshot of Remix Browser

  • The white space on the left side is the file browser. From here, you can upload files from your computer, publish all open files to an anonymous github host, copy all files to another instance of browser-solidity, and connect to localhost.
  • The centerpiece, where the ballot Solidity code is present, is the Solidity editor. This editor compiles the code each time it is changed.
  • The section on the far right is the tabs panel, where you can compile contracts, run transactions, adjust settings, debug / analyze your code and contracts, and obtain support through a community gitter chat.
  • What’s not present in the image is the bottom of the browser, which contains a javascript interpreter and the web3 object, and allows users to search data and clear logs from the terminal.

Truffle Development Framework

UPDATE: A circa September 2018 DappSeries related to this section is also available on Kauri @ https://beta.kauri.io/collection/5b8e401ee727370001c942e3/full-stack-dapp-tutorial-series

Smart contracts can be manually deployed using the solidity compiler, web3, and a functional node, though most find that this process is arduous and time-consuming. Truffle is a development environment that streamlines the deployment process. Official Truffle Documentation can be found at: http://truffleframework.com/docs/

Truffle is a useful tool that will automatically generate all the files and smart contracts needed to lift your project off the ground and into a more versatile environment. From here, Truffle can compile and deploy your smart contract to Ganache (a local test node), the testnets, or even the mainnet should you feel ready.

Quick installation via command line:

$ npm install -g truffle

Creating and initializing a project:

` $ mkdir NameOfMyProject $ cd NameOfMyProject $ truffle init

Truffle Output

Downloads… Unpacking… Setting up… Unbox successful. Sweet!

Commands: Compile: truffle compile Migrate: truffle migrate Test contracts: truffle test `

Truffle will create a set of folders: “contracts/,” “migrations/,” “test/,” and a truffle configuration file, “truffle.js.” From the command line you can compile, migrate, and test your smart contracts. Truffle Ganache is a test blockchain designed for Ethereum development. Ganache is TestRPC. Older articles will reference TestRPC, but both are the same tool.

For purposes of this document, we will install the Ganache command line interface: “ganache-cli.”

$ npm install -g ganache-cli

In your /NameOfMyProject/ folder, edit the “truffle-config.js” file to: module.exports = { networks: { development: { host: “127.0.0.1”, port: 8545, Network_id: “*”, } } };

With Truffle, it is easy to compile and migrate your smart contract onto the Ganache test environment. First, in one terminal start your Ganache test environment (by default it should start on port 8545):

$ ganache-cli

Now, in a second terminal, compile and deploy your smart contract, and then open the Truffle console:

$ truffle compile $ truffle migrate --network development $ truffle console --network development

Truffle’s console is basic interactive console for your Web3 libraries. For more in-depth documentation, as well as a list of commands, please reference Truffle’s official documentation: http://truffleframework.com/docs/

The functionality provided by Truffle is powerful. Users are able to rapidly compile, migrate, and test their smart contracts on a blockchain with just a few simple commands. Let’s pivot a bit and focus on another important characteristic of Truffle: it’s ability to integrate with other development environments. Zeppelin is one such environment that integrates well with Truffle.

Zeppelin Open Source Smart Contract Security Framework

An open source framework for developing secure smart contracts, Zeppelin provides users a collection of reusable, community-vetted smart contracts to assist users in developing secure dapps.

It is often advised, if such options are available, that existing proven and tested open source code should be reused when developing applications of any type. In the Ethereum space this advice should be duly noted, as smart contracts are inherently immutable once written to the blockchain. A unknowingly flawed smart contract written to the mainnet and operating in a live production environment can be and often are exploited by malicious actors, potentially resulting in lost or locked funds or inoperative smart contracts. OpenZeppelin saw this need and has provided a library of secure smart contracts that can be inherited by solidity.

Let’s install the OpenZeppelin open source framework and explore its functionality: $ npm install zeppelin-solidity

Turning back to the Truffle environment, using Solidity’s inheritance we can edit our smart contracts to inherit Zeppelin’s open source contracts, and then re-compiling and migrating back to the blockchain:

`pragma solidity ^0.4.17;

Import ‘zeppelin-solidity/contracts/token/StandardToken.sol';’

contract NameOfMyProject is StandardToken {

} `

The example ‘NameOfMyProject’ contract will now inherit all of the ‘StandardToken.sol’ variables and functions. For official Zeppelin documentation, please reference: https://zeppelin-solidity.readthedocs.io/en/latest/

Additional reading:

Building the Right Development Environment for Your Decentralized Application Needs

Lastly, as you move onto move beyond Remix and onto Truffle and other development environments, you may find that you need the ability to rapidly deploy customizable ethereum networks. If you need this functionality, then Puppeth may be the appropriate tool. Using Puppeth you can spin up a full ethereum network, including a bootnode, sealers (or also called validators), network statistics, wallet, dashboard, and even a faucet to dispense ether.

Integrated development environments all generally serve the same purpose: to streamline your development experience by allowing you to compile, migrate, deploy, and test your smart contracts. However, the various development environments all have their own flavors and opinions when it comes to how a decentralized app should be build. Knowing your personal development processes and your work style, it’s worth taking some time to review the varying nuances of some of the prominent environments we’ve listed below as you seek to find an optimal collection of tools to serve your development needs.

Other Development Environment Tools to Consider

Courtesy of list @ https://solidity.readthedocs.io/en/develop/index.html

Development Environments / Plugins:

Linters:

Additional reading:

Outline
  • Part IV - Developer Tools

OWNER
wil