Remix Project
Published in

Remix Project

Remix for Hackathons

So, you’ve signed up for a hackathon and need to get your development environment together. And, you’ve chosen Remix because there’s no set up required to get going. Maybe you’ve used Remix before, and maybe not. This guide will show you a number of tools that can help you use Remix to the max.

Let’s take a look at what you might encounter at a typical hackathon.

  • Learning and learning fast
  • Saving code — yes you’ll be writing code, but you better know where it is being saved!
  • Collaboration — often with other devs you have not met, often with devs who are not in the same room, and often with devs using other tools like Hardhat or Truffle. Remember, you’ll be doing more than just coding, you’ll be coding and explaining your code, justifying your code, and asking for HELP!!!
  • Importing code from other projects
  • Using normal development tools like debugging and unit testing
  • Deploying to multiple chains
  • Prototyping a front end — at least to prove to a judge that your code is working

Learning

Learneth Plugin for Remix and Solidity Tutorials

Remix has a tutorial plugin called Learneth that has tutorials right in Remix.

You can active it by clicking on the LEARNETH button on the home tab or by clicking the Plugin icon at the bottom of the icon panel.

The Solidity Beginner Course, walks you through examples presented on Solidity by Example, which is another great resource for learning Solidity.

Remix Docs and Articles

For getting up to speed on Remix, check out the Remix documentation and the Remix Medium publication.

Saving Files in Remix

Remix is not like a Google doc that saves work to your account on Google servers. Remix has no user accounts. By default, Remix only saves your code to your browser’s storage. However, if you run a terminal script called Remixd, you can save your work to a folder on your hard drive.

Should you save to your computer’s hard drive or to browser storage?

Saving to Browser Storage

The default behavior of Remix is to save files to your browser’s local storage. Take note:

  1. If your browser crashes or if you clear you browser storage, you can lose your work. But you can backup your work by PUSHING to GitHub or IPFS -using the DGit plugin.
    See this article and this article for more info about DGit.
  2. Browser storage is inherently limited to 5–10MB (depending upon how you count it), although in the next Remix release we will be integrating IndexedDB which will vastly increase the browser storage capacity when using Remix.
NEWS FLASH: IndexedDB is now available now on Remix-alpha and will be on Remix in the next release coming in a few weeks.

Saving to a Folder on your Computer’s Hard Drive with Remixd

Did I just hear you say, “WHAT??” Can Remix let you break the browser’s security sandbox? Yes, when running the script Remixd, you must specify a folder on your hard drive that Remix is allowed to read and write to, as well as the specific Remix URL, so that only the Remix web app is allowed to access your machine.

In Remix’s Files Explorer, in the Workspaces pull-down, select the -connect to localhost- option.

Then a modal will appear with more instructions.

Once Remixd is running, you can run Git from a terminal command line to push and pull to remote repos.

When using Remixd, you don’t need DGit because you are handling the version control on your hard drive — and you do all your pushing and pulling from there.

See the Remixd docs for more info.

Collaboration: Sharing Repos

You’ll probably be sharing a remote repo on GitHub. So if you are using Remixd, you will be pushing and pulling using GIT on the command line from you computer’s terminal window.

If you are not using Remixd, then you’ll be using the DGit plugin to manage Git.

Here are a few details about DGit, because many of you don’t know about it. (For even more info about it see this article and this article.)

Using DGit, you can clone, push, and pull to remote repos.

You can see diffs — side by side or on top of each other.

In the CHANGES section, click the name of a file.

In Remix’s editor, a tab will open with the diff:

You can view side by side, or not side by side by checking the side by side box.

Hackathons Require Collaboration: Sharing Examples with GISTs

Creating a GIST of file or a folder is easy in Remix — just right click in the Files Explorer.

You may need to add your Git access token using the Settings tab of Remix by clicking the gear icon at the bottom of the icon panel.

Explaining Your Logic to Others

At hackathons, you are most often designing new software, so to be most successful you need to explain the logic of your code. Fortunately, there are tools for that.

NatSpec Comments

Do you know about the special comments called NatSpec that you can put into Solidity? These get compiled into the contract’s metadata, and can be used for lots of interesting things like the EthDoc Generator — see below.

To learn more about NatSpec go here: https://solidity.readthedocs.io/en/develop/natspec-format.html

EthDoc Generator

To first activate the EThDoc Generator, you might also need to activate the EThDoc Viewer. The EthDoc Generator grabs the @dev section of the NatSpec comments in your code, and generates a file in a tab of the main panel.

It will list out all the functions and their inputs.

This doc only resides in the EthDoc documentation viewer and cannot currently be exported. But, you can make a series of screenshots with it to explain some logic.

Importing Solidity Code

At hacks, you’ll need to import some files — either to start ripping apart someone else's files for your own nefarious scheme (AKA to edit) or to import a library or a dependency (for files you won’t be editing).

Importing Files to Edit

To import a GIST, or from GitHub, IPFS, or via HTTPS, use one of the buttons in the IMPORT FROM section of the home tab. See bottom of the image below:

Importing Dependencies

The dependencies do not need to be “preloaded” into the Files Explorer’s current Workspace before the contract is compiled.

Files loaded from the import statement are placed in the Files Explorer’s current Workspace’s .deps folder. Under the hood, Remix checks to see if the files are already loaded in the .deps directory. If not, it gets them via unpkg if it is an NPM lib.

Here are some example import statements:

From NPM

import "@openzeppelin/contracts@4.2.0/token/ERC20/ERC20.sol";

From GitHub

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.5.0/contracts/math/SafeMath.sol";

See the Remix docs about importing for more info.

Also, if you are starting with an Open Zeppelin project, you should check out the Open Zeppelin Wizard. Remember to use the Open in Remix button!

Fetching Verified Contracts

Verified contracts can be fetched with the Sourcify plugin. You can activate the plugin in the home tab or go to the Plugin Manager. Use the Fetch button in the plugin and let it rip.

Working with Others Who are Developing on Hardhat

To use a Hardhat project in Remix, you need to be running Remixd.

Hardhat projects are npm projects with the hardhat package installed and a hardhat.config.js file. –Hardhat documentation

Remixd looks for the hardhat.config.js file in a shared folder, and if it finds the file, the Hardhat websocket listener will run.

Compiling

In the Solidity Compiler, right above the Compile button, there will be an additional checkbox that says Enable Hardhat Compilation.

Check this box and click on Compile.

When the contract is compiled in Remix, Hardhat’s compilation will also be performed with the compiler configuration defined in the Solidity Compiler plugin. A file named remix-compiler.config.js will be created in the root directory of the project. This file holds the compiler configuration from Remix.

The result of the Hardhat compilation will be shown in Remix’s terminal

Deploying to a Hardhat Chain

Remix has a plugin called Hardhat Provider to add an additional choice in the ENVIRONMENT section of the Deploy & Run plugin.

For more info check the Remix Hardhat docs and our post about Remix Hardhat integration.

Debugging Tools Including the Debugger

console.log

Debugging can include more than just using the Debugger. For example, one of Hardhat’s most popular features is their console.log. Remix has this functionality too — you just need to use the line

import "hardhat/console.log";

And put console.log with the variable you’d like to display.

And the log will display in the Remix console.

You can also use this with the Solidity Unit Testing plugin.

For more info about console.log, check the docs.

Debugger

To launch the Debugger, click the debug button in a transaction receipt in the Remix terminal.

For a quick intro to the Debugger, you can use the sliders or the step buttons to move around the code. And by adding break points you can jump add stops and assess what the state and local variables are.

For more info on the Debugger — check this post and check the Remix Debugger docs.

Deploying to L2

In most cases, L2s run Solidity. As a result, in most cases you just need to develop in Solidity as you usually would, and compile. When you deploy, you need to choose Injected Web3, and then choose the L2 of your choice in Metamask. But to deploy to an L2, you need to have its currency in your metamask account!

Starkware

Starkware is a bit different because it is written in the Cairo language. Remix has a Starkware plugin that allows you to develop in Cairo.

To try this out, you need to have a .cairo file to compile.

Getting the Front End Together

Generating a Contract’s ABI

To get a contract’s ABI, compile the contract and click the ABI button at the bottom of the Solidity Compiler.

Getting Up to Speed on ethers.js

Running Scripts in Remix

You can run async/await scripts that use web3.js or ethers.js.
Right click on a script to run it.

Showing a Judge the Contract in Remix

If your contract is working, you can show a judge Remix with the Deploy & Run plugin active. And interact with some functions there. They’ll get the idea.

Good Luck Out There!

Now go get BUIDLING!!

Remix is Looking for Beta Testers

If you like to help improve Remix please fill out this form.

Remix Gitter and Discord and Twitter

Please join our public Gitter channel and our Discord channel. On Twitter we are EthereumRemix.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store