jmather

Explorations in Ethereum

Blog Post created by jmather on Aug 4, 2016

When I first heard about Bitcoin it must have been in 2009 or 2010, It seemed a regulatory nightmare with huge disruptive potential that most regulatory bodies would never let come to fruition. Somehow though, there was something about it that was intriguing and it just kept taking hold. All said, Bitcoin had and has its issues. One big one is the sophistication required to created decentralized applications using Bitcoin. Along came Ethereum, where in theory, you can achieve decentralized applications by joe brogrammers like me . In Ethereum the hard cryptographic security is taken care of by the protocol itself, freeing you up to focus on what you want your application to do, not with how to manipulate the protocol.

 

To get an overview of the differentiating factors of Bitcoin and Ethereum, you can watch this video starting at the 6 minute 50 second mark and to quote Joseph:

 

https://youtu.be/0ilYnuP1qd4?t=6m50s

 

"The essential differentiating element between Bitcoin and Ethereum is what you can do on it and that’s enabled by the virtual machine and the programming language. In Bitcoin there’s a very simple virtual machine at each node and a very simple programming language. You can only write a very limited class of programs. On Ethereum there is a general purpose computer or virtual machine at each node and a very rich programming language so you can write whatever you can dream up, essentially."

 

So, this got me wondering, how difficult is it to do a hello world in Ethereum. Well, it turns out, if you follow the tutorials in Ethereum, they have an example of this known as the "greeter" app. If you have ever tried this you will realize that it is actually a bit more difficult than it might seem. I'm hoping this tutorial might be a bit easier. So, get ready and fire up your console as here are the "YMMV" Instructions on how to make the greeeter/hello world app function and process transactions in Ethereum. If you don't want to do this and just want to learn a little bit more about ethereum, skip below and read the excellent beginners guide to ethereum.

 

Step 1: Install geth (go based ethereum command line interface)

Step 2: Launch geth in developer mode (this will keep us from downloading the entire blockchain and allow us to more easily mine our own ether.

  • geth --dev console
  • Make not of the ipc folder (it is in a non-standard location when using developer mode), you will need this in Step 6

Step 3: If you haven't already create your own test account now (inside the geth console)

  • Personal.newAccount()

Step 4: Check your account balance (if you have not mined any eth before it should be 0)

  • eth.getBalance(eth.accounts[0])

Step 5: Start the miner and let it run

  • miner.start()
  • This will output a lot of logging so in the next step we will remedy by attaching to the console via the ipc mentioned in Step 2

Step 6: Attach to the console

  • geth attach ipc:/var/your/path/to/etherecum_dev_mode/geth.ipc

Step 7: Ensure that your account balance has increased via the mining that is running in Step 4

Step 8: Go to the online solidity compiler (this is the compiler that will compile your dapp, don't worry about installing your own, trust me, for now just use the online one)

  • https://ethereum.github.io/browser-solidity
  • Now copy and paste your code into the left hand pane of the compiler (this code can be found in the greeter link mentioned above) and it should compile your code with output into the right hand pane:

Step 9: On the right hand pane of the compiler, copy the Web deploy portion of the code (preferably to a text editor) and then modify the portion of the code to have your own message here:

/* var of type string here */

Step 10: Go back into your attached geth console and unlock your account you created

  • personal.unlockAccount(web3.eth.accounts[0]);
  • Ensure you have your password for your account when you run the above as you will be prompted for it

Step 11: Copy the code from step 10 into your attached geth console

Step 12: You should now have received a "Contract mined!..." message with the contract address

Step 13: Now within a short period of time (about 1 minute) you should be able to run:

  • eth.getCode(gretter.address);
  • This should return anything other than "0x", indicating your greeter/hello world contract is live!

Step 14: Now you should be able to run the greeter:

  • greeter.greet();

Step 15: This should return your greeting string that you modified in Step 9

  • This means that you can now theoretically offer this greeter dapp to anyone else for execution by having them create a contract with your ABI (Application Binary Interface) and the address of your greeter with code like below:
  • var g2 = eth.contract([{"constant":false,"inputs":[],"name":"kill","outputs":[],"type":"function"},{"constant":true,"inputs":[],"name":"greet","outputs":[{"name":"","type":"string"}],"type":"function"},{"inputs":[{"name":"_greeting","type":"string"}],"type":"constructor"}]

... ).at('theGreeterAddress');

 

Step 16: Now we have completed the greeter tutorial in a hopefully more friendly walkthrough than the one on the Ethereum website itself! The final step is to cleanup our greeter since we will no longer be using it. If we con't do this, it will leave the abandoned contracts on the blockchain, and in the future, it is noted that we may have to pay rent to use the blockchain. This of course is on the dev network, but it is still good practice:

  • greeter.kill.sendTransaction({from: eth.accounts[0]})
  • This should output something like: "0xf8341d41b7aa69bfbb31ff851b2e39897c4b054bccd9b5c54c19917d3988f561"

 

If you made it through that, congratulations and let me know your feedback!

 

Outcomes