Ethereum 101 on Windows

background / baseline context

  • I’m not even remotely suggesting that this is new info but even though there’s some very friendly guides already cooking out there, I ran into mild snags and this is my attempt to really grease the rails on the way to running the greeter sample smart contract
  • now that we have Ubuntu running natively on Windows 10 this, the native windows binary path for what are obviously linuxy bits sorta feels like a less direct path to success but IIRC i had initial snags that kicked me in this direction
  • these commands target a local private net instance… we get free gas this way so i figure inhale that immediate gratification as quickly as possible and use that energy to conquer our next ether mountain

getting spun up and ready to spend some ether

  1. feels like the canonical starting point so keep that handy -BUT- for starters, the referenced Windows binary installation url was down for me as of this writing
  2. so here’s the geth install bits… geth is the preferred CLI based server and admin console (installed to C:\Program Files\Geth for me)
  3. and we’ll also need the smart contract compiler “SOLC” (C:\Program Files\cpp-ethereum)… make sure those are both in your path
  4. create a working folder for this instance (aka “private network”) and make it current, hereby referred to as {workdir}
  5. throw together a genesis.json like so, filling in the as blanks as noted (from here 1)

    • nonce: throw in a self generated hex guid … one way to create a guid would be to install ScriptCS.exe and then System.Guid.NewGuid().ToString("n") … recommend installing ScriptCS and anything else via Chocolatey Windows package manager
    • coinbase & alloc: note that later we’ll replace those “0x0” values with your primary account number as where you want your mined ether to deposit and build up
  6. initialize your working folder files:
  7. do ourselves a big favor and create a default javascript file to toss in any of our own custom convenience routines to be available whenever the server starts up… save the following to e.g. helpers.js (referenced in the ethStart.cmd below)

  8. save the following to ethStart.cmd and launch it to fire up the server

    • 2 full CLI option reference
    • networkid: make yours up
    • datadir: crucial your other files are in the current working folder
    • dev: developer mode… this seems to make certain initialization steps do a faster minimal burn
    • unlock: this will prompt you for password and thereby start server with specified etherbase aka coinbase account unlocked to enable spending ether which is REQUIRED TO SUBMIT ANY TRANSACTIONS, including our first hello world sample smart contract!! =)
    • etherbase: update this with your primary account, next step…
    • password: create pw.txt with the same password you specify in next step…
    • rpc: fire up the http-rpc endpoint… defaults to: http://localhost:8545
    • preload: loads our custom convenience routines
  9. create your primary account: personal.newAccount("fill in a password") … this will output the hex number of your first account# aka primary aka eth.accounts[0]
  10. stop the server with CTRL-D
  11. plug this account# into genesis.json and ethStart.cmd > coinbase & alloc properties… and add the unlock parm back into ethStart.cmd
  12. drumroll… restart ethStart.cmd … watch for any errors in the output
  13. i had to wait a few minutes for mining activity like below to kick in… it would be interesting to hear what it’s doing during this extended delay…

    • definitely try miner.start(1) from the geth javascript command line if nothing happens after say 3 minutes tops
    • good troubleshooting ref 3
  14. once you see mined block output, then try balance() and you should see a few ethers piling up in your kettle
  15. here is my actual full happy output for your reference… don’t worry, all “secret” values herein (e.g. account#, password, etc) are local testnet only / completely sacrificial

    saving “greeter” sample smart contract to your blockchain

    now we can jump into the greeter hello world sample

    1. save this to greeter.js

    2. fire that greeter.js which compiles the greeter contract and send it off to be committed to your blockchain via: loadScript("greeter.js")
      • expecting output:
    3. again, sit and twiddle your thumbs for an excruciatingly long time (7 minutes for me!?!?)… and hopefully you eventually see output
    4. now we finally get to do: greeter.greet()
      • expected output


    Fun next steps…

    1. Get BlockApps Strato rolling

    • Strato4 is a convenient REST API layer on top of raw Ethereum

      Each BlockApps node exposes a RESTful api to interact with the node. This allows you to deploy contracts/publish transactions with simple REST calls. Bloc-server also generates a REST api for each smart contract you deploy with it. This allows for a clean separation from your dapps frontend and smart contracts

    • Solidity extension for Visual Studio has an nicely easy run through on setting up BlockApps

    • BlockApps Strato GitHub Readme is also short install guide with the following steps
    1. install nodeJS / npm via: choco install nodejs
    2. npm install -g blockapps-bloc
    3. test your Ethereum dev net apiUrl is listening: curl http://localhost:8545, expecting output: {"jsonrpc":"2.0","error":{"code":-32600,"message":"EOF"}}
    4. create a fresh BlockApps project…
      1. CD into PARENT directory of your new project folder
      2. block init and follow the prompts – the Visual Studio extension link has nice screenshots
      1. then CD into your project folder
      2. bloc genkey – will prompt for password and create initial “admin” user, expecting output: transaction successfully mined!
    5. bloc start fires up the Strato server listening for REST requests, expecting output:

      • that’s pretty cool we’re running on top of our own custom dev net
    6. (open yet another CMD window) curl "http://localhost:8000/users", expecting: ["admin"]
    7. continue on with the guides…
    8. particularly this Ether transfer example
      • tip, curl "http://localhost:8000/users/admin" yields the necessary user address number
      • sample transfer: curl -X POST -d "password=ann0ying&toAddress=39b32d2be0c29c1011f7d1481f945b9d355cae96&value=10" http://localhost:8000/users/admin/a962a8e09ae6a096258d988588f2e8639cd2a664/send
      • ran into this error: {"errorTags":["transactionResult","submitTransaction","Transaction"],"message":"txHash must be a hex string (got: [object Object])"}
      • only mention of this kind of error i’ve found so far has no response
      • i got node.exe JS file breakpoints working in Visual Studio 2015… a little tricky because bloc “spawn”s the main web listener as child process… so basically tweak this %appdata%\npm\node_modules\blockapps-bloc\bin\main.js line as so var server = spawn('node', ['--debug-brk=5859', 'app.js' ]); and follow this VS guide
      • debugging showed me the underlying error back from ethereum is missing request id… which i ran across firing basic curl requests at ethereum when i left out {“id”: number} on my curl calls… so i hacked that into the source {myProj}\node_modules\blockapps-js\js\Transaction.js but then…
      • the next error i’m stuck on now is The method _ does not exist/is not availableso something is off
      • even though Strato is basically happy with my Ethereum install enough to execute the new user APIs no problem
      • i posted issue on their forum
      • [update 2016-12-24] not only did support respond promptly next day but it was Kieren James-Lubin (kjameslubin) the founder no less! turns out, quote: “You must run a Strato node to be able to use bloc. No other Ethereum client supports it… You can use or launch one from the Azure market place or contact us at to install.”… so, that is welcome clarity straight from the horse’s mouth… a rare luxury that i am grateful for on this christmas eve… we’ll hop over to those other options … and the adventure continues… 🙂


    2. get cracking on some real DAPPs!!


    Handy References