4 tools to 3x your productivity in Remix as a solidity developer

4 tools to 3x your productivity in Remix as a solidity developer

Introduction

Every solidity developer used remix in writing smart contract code. Some developers still do. One of the reasons developers use remix is the interface it provides for interacting with deployed smart contracts. It takes a while and a good amount of experience using frameworks and other IDEs like VS Code or Sublime Text to interact with deployed contracts. Still, with remix, everything is available instantly.

However, remix can be used for more than writing smart contracts or interacting with them. The purpose of this guide is to show you four awesome tools on remix that will 3x your productivity as a solidity developer.

Why do you need these tools?

Time is every developer’s most precious asset. We sometimes find ourselves thinking about how to optimise our activities and learning so we can do what we need four steps for in two or maybe one.

Systems, tools or plugins that help increase productivity, like the ones in this guide, are important because, for example, they help you do intermediate-level testing without opening VS code.

Furthermore, you will also be able to use remix as a code viewer and an analyser, which checks for inconsistencies in your code. Even experienced developers use these tools from time to time. It is, therefore, important that you are familiar with these tools too.

Unit testing

Unit testing refers to the testing of individual components of a smart contract. There are two reasons why we need to test our smart contract.

The first reason is to ensure that the contract works as intended. For example, we can write a test to ensure that a user gets the equivalent amount of USDC in exchange for USDT in our contract, not AAVE.

The second is to determine if any vulnerabilities exist in our smart contract, which can be exploited by bad actors or bugs that can cause our contract to stop working as it should. Smart contract developers shouldn’t assume that everyone using their smart contract will use the contracts according to design.

To conduct unit tests in remix, you must activate the solidity unit testing plugin. To do that, you need to go to the plugin manager in remix, search for test, and activate the solidity unit testing plugin.

Smart contract unit testing boils down to the satisfaction of a condition which is why the assert library is important. It is how developers, penetration testers, and unit testers ensure that the expected is equal to the actual.

The assert library is a big part of unit testing in remix. There are five assert functions provided for testing in remix. They include:

  1. Assert.equal checks if a == b

  2. Assert.notEqual checks if a != b

  3. Assert.greaterThan checks if a > b

  4. Assert.lesserThan checks if a < b

  5. Assert.ok checks if a condition is true only.

Besides the assert library provided by remix, the plugin allows you to use the beforeAll, beforeEach, AfterAll and AfterEach functions. These functions will enable you to specify the default state of your contract

  1. Before all test functions run (BeforeAll),

  2. After all test functions run (AfterAll),

  3. Before each test functions run (BeforeEach), and

  4. After each test functions run (AfterEach).

We can also send a transaction or call a function with different accounts using natspec comments provided by solidity and incorporated by solidity unit testing plugin.

Unit testing is quick and simple to grasp. The remix team has provided an elaborate tutorial on how to get started with testing in remix. You can access the documentation here.

Remix’s Solidity Unit testing plugin is enough to conduct minimal-level tests; however, it is advisable to use a framework for elaborate testing.

Code Viewer

Etherscan as a code viewer is important but stressful to use. Looking through a protocol’s code on etherscan with 42 contract files can be demotivating. Remix as a code viewer is way better and easier. It allows you to view any code on Github and any deployed code on etherscan or its testnets.

Github

Viewing a GitHub code in remix is as easy as changing the URL in your browser's URL bar. I’ll be using the DateTime contract on my github as an example. To view this code in remix, all you have to do is replace github.com with remix.ethereum.org. Once the remix page is loaded, you should see the contract. You can compile the code and run it in remix if you want to.

Etherscan

Remix only supports contracts deployed on etherscan or its testnets at the moment. Viewing code from etherscan is as simple as changing the URL from etherscan.io to remix.ethereum.org. For this guide, we will use a lending pool contract I deployed on the goerli testnest. All you have to do is replace goerli.etherscan.io with remix.ethereum.org, and the code should be loaded into remix.

Solidity Static Analysers

Following best practices and ensuring your smart contract is secure is important. Many developers overlook the little things because, at the moment, they cannot possibly fathom or understand how these inconsistencies could be a bug or how they could lead to a hack.

A mistake such as omitting the onlyOwner modifier in your contract despite importing the ownable contract could lead to an access control attack which is either a high or a medium-level severity bug depending on many other factors.

However, there is a remix plugin that can help you catch different bugs or vulnerabilities in your contract. This tool is Remix’s Solidity Static Analysers.

This tool focuses on four aspects: security, gas and economy, ERC and miscellaneous. Irrespective of how great this plugin is, it is not a substitute for a proper audit. It only supports you as you code the logic for your smart contract while catching small errors you may have missed.

Go to the plugin manager and search for Solidity Static Analysis. Activate the plugin, and you should now be able to use the plugin.

We will continue with the lending pool contract we imported into remix in the previous section. Ensure the Lending Pool contract is selected in the deploy section of the remix environment; go to the static analyser and click on run. Autorun is usually chosen by default; you will need to uncheck it. Once you are done, the report should be presented, as shown below.

You can also check and uncheck some other operations in any of the four options if you want your analysis to be more focused.

Verify & Publish (Flattener)

Remix interface is cool, but it is nice to know how to verify a deployed contract. Understanding how to do this is important because a verified contract is considered legitimate (do not mistake this for security).

Verifying and publishing a single-file contract is quite easy to do. A single-file contract is a contract with no import statements. All the contract logic is in a single file, and you wouldn't need to import anything. All you need to do is copy and paste the code into etherscan, and your contract will be verified almost immediately.

Building an ERC20 token or a lending pool requires you to import a couple of contracts. At this point, your smart contract becomes a multi-file contract. Verifying such a contract on etherscan or any other block explorer is a bother.

Flattener is a tool to help you with multi-file contracts. It allows you to compress contract files into a single file which can be uploaded using the single-file system.

Like any tool in remix, we begin by installing the tool in the plugin manager. Search for flattener, and activate the plugin.

For this, we will also be using the lending pool contract. You need to deploy the contract on a testnest first. Once deployed, click on the contract address, and go to the contract section. What you will see is a byte code. You need to verify and publish before you can see the contract code and interact with the block explorer interface of your contract.

Once you click on verify and publish, the block explorer will ask about the choice of the compiler used, which can be found on remix. You also need to input the license.

Go to the flattener in remix and click on flatten <Contract Name>; in this case, flatten lendingPool.sol.

Ensure your code is compiled, or else you won't see this in the flattener tool. Once you click on the flatten LendingPool.sol button, the code is automatically copied into your clipboard. Go to the explorer, paste the code in, click on verify and publish, and viola, your code is verified.

Now to the interesting part, go to the contract section once your code is deployed, you will notice that you now have access to three new things, code, read contract and write contract.

Code shows you what code you have in your contract, read contract allows you to perform read operations with zero gas fees, and write contract allows you to write to the contract on the blockchain. This would cost you gas. There you have it, your code is live on the blockchain, and you can interact with it too.

Conclusion

As developers, productivity is really important. There are a lot of systems we need to learn and projects we need to build to improve regularly. This article aims to show you four tools to help you reach that goal faster and more easily. These tools have helped me save a ton of time as a solidity developer, and they will be able to help you too.

Follow me on Twitter and LinkedIn for tips on becoming a better solidity developer and smart contract auditor. You can also check my GitHub page for amazing solidity projects like the borrowing and lending pool used in this guide.

Keep Learning, keep building. WAGMI.