Debugging Solidity with a GUI (Remix) and Ganache

Shane Fontaine
Authereum
Published in
3 min readSep 19, 2019

Debugging Solidity is notoriously difficult. Tools like Ganache, Remix, and solidity-test-helpers have made it easier over time, but the difficulty still remains.

A GUI for debugging with Ganache would help alleviate many of these pain points and would allow a developer to visually transact and debug contracts. There is now a way to do just this!

This tutorial allows you to debug your local Solidity project with Ganache (instant transactions) and Remix.

The Setup

The following assumes that you have a Truffle project and are attempting to debug it with Ganache.

The steps to debug with a GUI are as follows:

  1. Install remixd
  2. Run remixd
  3. Connect your project to remix.ethereum.org
  4. Run ganache-cli
  5. Choose “Web3 Provider” as your “Environment” in Remix
  6. Debug your code with a GUI

Install remixd

In order to debug your contract with a GUI, you must first download remixd. remixd is a tool that is intend to be used with Remix IDE (aka. Browser-Solidity). It allows a websocket connection between Remix IDE (web application) and the local computer. To download it, simply run:

npm install -g remixd

Run remixd

You now need to run remixd to set up the websocket connection. You can do this by running the following command with the absolute path of your project:

remixd -s <absolute-path> --remix-ide https://remix.ethereum.org

Connect your project to remix.ethereum.org

Now head over to Remix. On this page, go to the plugins section by clicking on the icon that looks like a plug. Search the plugins for “remixd” and click “activate”.

The page will give you a warning that you are about to open a connection between your port and the page. Click “connect” and you will see your entire project appear in Remix! You should now see your local directory displayed in Remix.

Local directory in Remix

Run ganache-cli

Now you will need to spin up your local node—do this by running ganache-cli.

Choose “Web3 Provider” as your “Environment” in Remix

You now need to connect your local node (ganache) to Remix. Do this by clicking on the Ethereum looking symbol on the left side of Remix and then choosing “Web3 Provider” as your “Environment” in Remix.

You will get a popup about an external node request. All of the default options will work, unless you changed the port that your ganache node is running.

External node request

Debug your code with a GUI

You can now debug your local code with a GUI! You can deploy contracts and interact with them directly with the GUI.

To confirm this is working, feel free to deploy a contract and look at the transaction execute on your ganache node.

Conclusion

This type of debugging opens up a whole new world for Solidity. It broadens the tooling landscape for Ethereum developers and allows for both command line and visual debugging and testing. Remix offers a wonderful interface for coding and debugging, as well as an incredible (and growing) suite of plugins that you can now use to interact with your contracts.

Additional Features

There are a number of more advanced features you can perform with this setup. These include:

  • Flatten your contracts with the flattener plugin
  • Forking a live network and visually stepping through a failed transaction
  • Verifying contracts on Etherscan with the Etherscan plugin
  • Secure your contracts with the Mythx Remix plugin

--

--