A Jedi’s Guide to Ethereum — Part 3b(Remix)

The Network

Please refer to the previous articles if you have any questions about the steps below. We are starting Obi-Wan and Yoda’s respective nodes on Tatooine and Dagobah with a few additional parameters that will become useful later in the article.

Dagobah

Run the following commands to start up the dagobah ethereum node in a new terminal. Note the new rpc parameters. These are to be used to connect the node with our Remix IDE later in the article.

geth --datadir "~/ethereum/dagobah" --networkid 5555 --rpc --rpcport 8545 --rpccorsdomain "http://remix.ethereum.org"
geth attach ~/ethereum/dagobah/geth.ipc

Tatooine

Open a new tab in the terminal and start the Tatooine ethereum node. Note that the — rpcport value is different than the Dagobah value. This is because the port must be unique as we will connect a separate Remix IDE to each ethereum node. Also, note the — rpccorsdomain is http: NOT https:

geth --datadir "~/ethereum/tatooine" --networkid 5555 --rpc --rpcport 8546 --rpccorsdomain "http://remix.ethereum.org"
geth attach ~/ethereum/dagobah/geth.ipc

Connect the Nodes as Peers

Add the Dagobah node as a peer to the Tattoine node by running the following command in the Tattoine console.

admin.addPeer("enode://bffe12a6809d1e6664c9fffe8c5193cdb4e9d70640b0fbd729e1a5fd57f612674450486b1444fcdf6e7f91f42df0bb0a6707f8ae6637ec9b756075a8767dcde2@[::]:30303")
admin.addPeer("enode://af2293f6ef0cd9d253ed53850bdfc8b494539b1fb143e7df9269b6de7f67d4200a28beb0e4b2d63368cdc7e60fe1688413fe2f3423eabbba92f930224d26ed15@[::]:30304")
> net.listening
true
> net.peerCount
1

Start Mining

With our truffle network, deployment and transactions to the contract did not have to be mined. Now that we are using an actual ethereum node, we need to have miners running on both nodes. Note that in the real world, we probably would rely on external miners to process the transactions, but in this case we can simply run the following command in each console.

> miner.start()
INFO [01-11|12:10:24] Updated mining threads                   threads=0
INFO [01-11|12:10:24] Transaction pool price threshold updated price=18000000000
INFO [01-11|12:10:24] Starting mining operation
INFO [01-11|12:10:24] Commit new mining work number=296 txs=1 uncles=0 elapsed=1.040ms

Remix

Remix is an IDE(Integrated Development Environment) provided by the Ethereum Foundation to help with Solidity development and deployment to the blockchain. It comes as a standalone app or as a web app. For our purposes we will use the web app in Chrome. Go ahead and open up two new tabs in Chrome pointed here: http://remix.ethereum.org/ (Note the http: protocol and not https:)

Compile the Contract

Go ahead and open up the first Remix tab and click the plus icon in the upper left corner.

Connect Remix to Dagobah and Tatooine Nodes

Before we can deploy the contract anywhere, we need to connect our Remix IDE(s) to a respective ethereum node. We will connect our first Remix instance to Dagobah and our second Remix instance to Tatooine. Since we gave the nodes unique rpc ports upon starting them, we should be able to connect each remix ide to a separate ethereum node on the same machine. The process for connecting each Remix instance is the same besides the port number, so we will simply show Dagobah’s setup for brevity.

  • It will prompt you to confirm you want to connect to an ethereum node and then present an input box for you to put the ethereum node’s address in. Put http://localhost:8545 in for Dagobah.
  • Click OK, and you should be connected to the node that you input.
  • Repeat the above process to connect the Tatooine node to the second Remix IDE using http://localhost:8546

Deploy Contract

Open up the Dagobah connected Remix instance. We will use this instance to deploy the contract. Our Remix should look like this, though the amount of eth we have would vary. We only have one account created on the Dagobah node and that is defaulted as shown here

> personal.unlockAccount("0x0be3899c3e84e2015fe93788dee96b30fc48f0a6","yoda")

Place Bet

Now that we have deployed our Bet.sol contract, let’s go ahead and place our bet. For this we need to do a couple things

  • Set our guess in the input box to the right of the createBet button. In our case we guessed the number was 4.

Take Bet

Go ahead and open the Tatooine Remix instance and paste the copied contract address into the At Address input box and click the At Address button. You should see something similar to the following:

  • Set our guess in the input box to the right of the takeBet button. In our case we guessed the number was 6.
  • We need to login to our Obi-Wan account or the transaction will fail — do so in the Tatooine console as follows
personal.unlockAccount("0x8d17ee6f8171a1d8cc26851213d5dc3b1f08cc40","vader")

Results

The Bet has been completed, so let’s see the results and compare the contracts. Keep the Tatooine remix window open and examine the outcome of the bet. A couple things to note

  • The getTakerGuess and getOriginatorGuess have propagated between the contracts

Conclusion

Remix is an awesome tool for Solidity development. It is very helpful to use Remix alongside a tool like truffle to gain more insight into the code itself and into the contract’s integration into the ecosystem. I would actually recommend writing your code in Remix first to get the bulk of it correct and then tune it within the truffle framework.

--

--

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