Tip: Using Remix IDE

Project Source Code

Get the project source code below, and follow along with the lesson material.

Download Project Source Code

To set up the project on your local machine, please follow the directions provided in the README.md file. If you run into any issues with running the project source code, then feel free to reach out to the author in the course's Discord channel.

Table of Contents

This lesson preview is part of the Million Ether Homepage course and can be unlocked immediately with a \newline Pro subscription or a single-time purchase. Already have access to this course? Log in here.

This video is available to students only
Unlock This Course

Get unlimited access to Million Ether Homepage, plus 70+ \newline books, guides and courses with the \newline Pro subscription.

Thumbnail for the \newline course Million Ether Homepage

I want to give you another tip that will save you tons of time. When developing your smart contracts, use an IDE like Remix. In our videos, we've been compiling our smart contracts by hand using Sulk, and this is a good idea for learning what's going on and it's a best practice for production contracts. That said, when we're in the early development stages, copying and pasting byte code and ABIs can be a real pain. Thankfully, there are editors like Remix that make this a lot easier. And I want to give a disclaimer first. In this video and in this course, I'm going to be using Remix as a tool to quickly compile, deploy and experiment with smart contracts. I want you to know that Remix is not essential. You can and should be able to do anything I'm doing in Remix on the command line. We've covered how to do it in earlier videos. Remix is a tool to make our lives easier, but it's not a requirement. Another thing I want you to keep in mind is that Remix is under active development. I'm using the most recent version of Remix, but by the time you're watching this video, the design might have changed a little bit. If you see me using a feature that doesn't appear in the same place in your version, check the comments section for updated instructions. With that in mind, let's take a look at Remix. There's a deployed version of Remix at remix.etherium.org. You can also find the code at GitHub. In the main pane, you can see some default Solidity code. On the left, we have our file explorer, and on the right, we have some tools. For our development, we need to connect this page in two ways to our local computer. One, we're going to connect the Remix file pane to our local file system using a tool called RemixD. And two, we can connect this page to our local Geth test network using Web3. Keep in mind that we need to be very careful about security here. It's probably fine in this case to connect to your local Geth instance as long as it doesn't hold your real private keys. That said, if you want to be extra careful with your security, I'd recommend downloading Remix from GitHub and running a local instance instead of using this hosted instance. The hack scenario here would be where an attacker hacks the hosted version of Remix and secretly configures it to steal your private keys. This hasn't happened yet that I know of, but better safe than sorry. Let's connect Remix to our local file system using RemixD. You can view the GitHub repo for RemixD here, which gives you installation instructions. Right now it uses NPM install. We use it by starting RemixD and passing the path to the directory we want to use for our contracts. Now, back in Remix, we can click the chain connect icon above the file browser. And if you're lucky, it will connect to your local RemixD. Here you can see that I'm working on the million ether page.soul. Remix can run our code in a variety of environments. The default environment is a JavaScript implementation of the EVM. The JavaScript version is really fast, but it all runs within our browser. Instead, what we're going to do is connect to our local Geth node. This will let us use Remix as an interface to our local durable blockchain. We can also perform actions on the Geth console that affects state, and we'll be able to create a web UI that also reads from that same Geth. By connecting to Geth, we can use it as a central access point. In order for this to work, you need to have started Geth with the correct RPC options. Here's one Geth command that would work, though we'll use others in other videos. To connect to our local node, we'll pick from the dropdown web3 provider. Right now the default says localhost port 8545. I have to use 127.0.0.1 to connect to my machine. If it worked, you should see your accounts dropdown change. Within this Geth instance, I already have some accounts, and so they appear in the dropdown along with the amount of ether in each account. If we click the contract details, you can see a number of helpful info panels. For example, we can see the compiled bytecode, the ABI, the gas estimates, and even the assembly. Deploying an instance of our contract is super easy. We can create an instance on our blockchain by hitting Create. This will submit a transaction to our Geth node. And remember, you'll need to mine this and any transaction you send there, so make sure that you have a minor running. After we deployed, you can see that we have an address for this instance. We can copy this address, save it, and use it in the Geth console or in our apps. Notice that Remix also reported the amount of gas required to create this contract. Another thing you might notice is that the methods on our contract object now have form fields. One of the best things about Remix is that now we can use these forms as a minimal UI to test our contracts. Let's test it now. In this contract, we're storing an array of arrays of pixels stored as bytes 3. We can get the value of any particular pixel by using the pixels function. If we wanted to get the pixels at say 74, you can see that it returned 0. To set the color of a pixel, we need three arguments, the x index, the y index, and three bytes. The x and y index are easy enough, we just pass the numbers themselves. But passing three bytes is a little awkward. What we have to do is pass each byte itself as a hex encoded string. So here we have an array with three bytes, each byte individually encoded as hex. After we submit that transaction in its mind, we're given back a transaction receipt, which we can inspect to find the block number of that transaction as well as the amount of gas used. Notice that the from field is our account address, and the to field is the address of our contract. Our contracts account address lives on the blockchain like any other address. Another thing you can do with remix is debug particular transactions. I'm not going to walk through it here, but click on the launch debugger button to walk through the EVM opcodes that happened during our transaction. Now we can check the value of the pixel 74 by using pixels again. Notice that it returned our color in hexadecimal. Nice. Let's say that you refresh the page and you want to get set up again. You'll need to reconnect to remix D and also to your web3 provider. If you want to reuse an old contract, you can click the at address button and then paste the address of an already deployed contract. This will let you interact with that contract and keep its state. So that's the basics of remix. It might change a little by the time you watch this, so check out their docs for the latest. And you don't have to use remix, but we're going to be using remix a lot in these videos and it's going to save us a ton of time. [BLANK_AUDIO]