Our thoughts on Ethereum

KPCB Edge
8 min readNov 24, 2015

--

As investors with a focus on blockchain technology, we’ve seen quite a few companies building on top of the Ethereum ecosystem since the developer preview launch a few months ago. For the unfamiliar, Ethereum is “a decentralized platform that runs smart contracts.” You can learn more about Ethereum on the Ethereum website, and there’s a good summary of its most important characteristics on Wikipedia.

We wanted to familiarize ourselves with Ethereum the way we know best — by making some demos and seeing what’s possible on the platform. Here, we’re sharing some simple instructions on how to get started with Ethereum and some thoughts on why we’re excited by it. We’ve built a few more complex contracts as well, which we’ll talk about in a follow-up post in a couple of weeks.

Though Ethereum is still quite early, we’re extremely excited by the kinds of applications it makes possible, and we’re also excited by the strong developer adoption we’ve seen firsthand in the last few months. We believe Ethereum is a powerful addition to the Blockchain development toolchain, giving users access to distributed computation and mutable storage that is censorship-resistant and tamper-evident.

We’re also encouraged by projects to build alternative implementations of the Ethereum VM (EVM) on other blockchains, such as Rootstock or Counterparty. We think these are early signs of convergence towards EVM bytecode as a common low-level language for contract programming, but only time will tell if EVM bytecode becomes the dominant contract language, and if Ethereum remains the most commonly used implementation of the EVM. From our perspective, the existence of projects like this could reduce the platform risk founders are exposed to when building their product on Ethereum.

We’re still most excited by companies using blockchains as a deliberate architectural choice in their stack, but in a way that’s invisible to end users. From a user’s perspective, we believe these services will be cheaper, faster, and more secure than ever before (more in the introductory blog post for our blockchain technology investing thesis). We think Ethereum as a software platform significantly adds to the potential ways blockchain technology could be used in an application’s technology stack.

If you’re a founder at a company using blockchain technology, we’d love to chat!

Setting up Ethereum

Note: These demos were written / executed on an OS X machine, but the same instructions should work without modification on Linux and with minor tweaks on Windows. These instructions assume a basic familiarity with what Ethereum is, how blockchains work, and software engineering more generally.

To get started with Ethereum, install the Ethereum go client by following these instructions. With Ethereum installed, you should start syncing the Ethereum blockchain to your machine by running the `geth` command with no arguments in a shell (meant to be run as a daemon, but for local testing I found running it in an interactive shell to work fine). Syncing the blockchain takes quite a while; you can check your progress by looking at the block count at the end of each log messages from the daemon and comparing it to the total on this Ethereum dashboard. The rest of this demo assumes you have the daemon running, so leave this shell open in the background.

While your blockchain is synchronizing, you can set up an Ethereum account locally. You will need to have some Ether, the currency that underpins Ethereum, stored in a local wallet to be able to deploy contracts. Ether is the currency of computation in Ethereum, and is spent to deploy / interact with contracts in units of “gas”, which has a dynamic price set by the network. Current gas price can be checked by looking at the Ethereum dashboard from above.

In a second shell, run `geth account new`, set a password for the account, and note the address returned. There’s more on account creation / management in the Ethereum documentation.

Now, you will need to purchase a bit of Ether using an exchange like Poloniex or Kraken (easier if you already have some BTC you can send there and exchange for Ether), or acquire some through one of the other methods described on the Ethereum website, and send it to your local account address. Very little Ether is needed to get started — running the demos below could easily be done with 0.1 Ether, which costs about $0.10 at the time of writing.

Once your blockchain has finished syncing, which can be verified by checking your block count against the Ethereum dashboard linked above, and you have a bit of Ether deposited in your new account, you’re ready to deploy your first contract. You can check your balance by opening the Ethereum console; type “geth attach” in a new shell, and run `web3.fromWei(eth.getBalance(“ACCOUNT_ADDRESS”), “ether”);` where ACCOUNT_ADDRESS is the address you got earlier.

`geth attach` is your entry point to the Ethereum javascript console, which provides a basic javascript execution environment with some Ethereum extensions, A full command reference can be found on the Ethereum wiki.

Deploying your first contract

To familiarize yourself with the contract deployment process, I suggest deploying a simple Hello World contract, which I took from the very extensive Ethereum contract tutorial:

contract mortal {
/* Define variable owner of the type address*/
address owner;
/* this function is executed at initialization and sets the owner of the contract */
function mortal() { owner = msg.sender; }
/* Function to recover the funds on the contract */
function kill() { if (msg.sender == owner) suicide(owner); }
}
contract greeter is mortal {
/* define variable greeting of the type string */
string greeting;
/* this runs when the contract is executed */
function greeter(string _greeting) public {
greeting = _greeting;
}
/* main function */
function greet() constant returns (string) {
return greeting;
}
}

This contract is written in Solidity, a Javascript-like language which compiles to bytecode that can run on the Ethereum virtual machine. All that the greeter contract can do is return the string we provide, in this case “Hello, world!” or something similar. The “mortal” type gives us a straightforward way to terminate the contract when we’re finished with it, which will send any funds in the contract back to the address that originally created it. The mortal contract could be used as the base for any other contracts you may write — Solidity supports a complete inheritance model for contracts.

To deploy this contract, you will need to compile it to EVM bytecode. To do this securely you should build a compiler locally, because an online compiler could be compromised to produce code you don’t expect it to. For demo purposes, however, using the web-based Solidity compiler should be fine.

Assuming you are using the web-based compiler, all you need to do is paste the greeter code into the editor to get the compiled bytecode on the right. Conveniently, the right pane also includes a Javascript snippet you can run in the Ethereum JS console, titled “Web3 deploy”. Note that you will need to fill in a greeting at the top of that snippet for it to run in the Ethereum console. You will also need the “Interface” snippet later.

Now, open a new Ethereum JS console by running `geth attach` in a new shell, and paste in the Web3 deploy snippet. Within a few minutes, you should see a message stating “Contract mined!” along with the address the contract now lives at. You just deployed your first Ethereum contract — congratulations!

You should be able to look up your contract through public block explorers like https://etherchain.org/ by searching the transaction hash, and even see the code that was deployed. Note down this address as you will need it soon to interact with the contract.

To interact with the contract, in the same console, run `greeter.greet();` and you should get back the string you entered earlier. Because getting the greeting doesn’t run any code on the blockchain, this operation costs 0 gas. The `greeter` object was instantiated when you pasted in the Web3 deploy code snippet, but can also be set up independently, so anyone can run it without needing a local copy of the source code.

To show how a friend could run the same greeter contract on their local Ethereum node, we can run the same contract from a fresh console environment. Close your Ethereum console by running `exit`, and run `geth attach` again to reopen it. To verify that you’re in a clean console environment, run `greeter.greet()` and you should get a reference error that the name greeter is not defined. Now, instantiate a new instance of the greeter by running `var greeter = eth.contract(ABI).at(“Address”);`, where ABI is the “Interface” snippet the solidity compiler produced earlier, and Address is the address the contract was mined at. Now, you can run “greeter.greet()” and get back the same message you got earlier.

An important note here is that the string you specified is now stored in the blockchain, and accessible by anyone; you could even create a function allowing only you as the contract owner to change it.

I have another greeter at address “0xb55f89461a273f8dbde74a92cdc752d86427476b”, and it uses the same “interface” snippet that the Solidity web compiler will give you for your greeting contract. For bonus points, you can see the message I wrote in my contract by running the greet function for it too.

This may seem trivial, and from a developer’s perspective it is; you’re running a very simple hello world program and it’s producing the output you expect. What’s really interesting here is that this code now lives on the Ethereum blockchain, and has access to storage and computation that is highly distributed, censorship-resistant, and tamper-evident, without requiring you as a developer to build your own distributed infrastructure.

To kill your contract, run `greeter.kill.sendTransaction({from:”ACCOUNT_ADDRESS”})`, where ACCOUNT_ADDRESS is the address you got when creating your account earlier. After this, your greeter can no longer be run.

I glossed over some details here, but hopefully you’re intrigued enough to learn more! I wasn’t able to cover some of the projects we built, so we’ll publish a follow-up post in a few weeks.

--

--

KPCB Edge

KPCB Edge is a team of builders, investing in seed stage founders working on emerging areas of technology. | www.kpcbedge.com