Ethereum on a iPhone – Decentralize Today

Ethereum on a iPhone

Getting embarked with Ethereum apps on iOS

There is no installation package, build by the Ethereum community, ready for the iOS. But in a way it is possible to build something.

Let us commence with the Ethereum client architecture to see what we have.

Ethereum is an example of a very rapid growing blockchain implementation. Actually, Ethereum has surpassed Bitcoin in amount of knots in the public network, at this writing moment, see the current number of knots.

Ethereum is a cryptocurrency. Ether is the currency. Ethereum was created as a clone of the Bitcoin core, having its own blockchain network – a public, distributed ledger. The Ethereum network is called “P2P Wire Protocol Network”.

The most exceptional: Ethereum has a entire programing platform on top of its cryptocurrency, implemented in every client. The programs are called DApps, Decentralized Applications.

People are doing things in Ethereum that are not possible right now in Bitcoin. It has created a fresh generation of developers which never worked with Bitcoin but are interested in Ethereum. See story from Coinbase. What is very real, however, is the possibility that Ethereum blows past Bitcoin entirely. See

Ethereum Client

Every knot in the network is called a Ethereum Client — and it has nothing to do with a client-server architecture. There are only “clients” knots in the Ethereum network.

Where the Bitcoin blockchain distinguish inbetween a full-node, having a total copy of all transactions, and a lightweight knot, having only what is needed for a wallet, the Ethereum has only full-nodes. But there is being working on a lightweight knot, see what-should-i-install-on-a-mobile-tablet. Meaning, we must wait on the official Light Client for the mobile devices.

While we are waiting on a lightweight solution for iOS and Android, let us dive into the ‘full-node’ client architecture and see what we already have to work with.

The Ethereum Client consists of:

  • Network routing, detect and maintain connections to other clients in the P2P Wire Protocol Network.
  • The blockchain database, having a copy of all transactions.
  • The mining, the work with creating, verifying, publishing and propagating blocks in the blockchain, ensuring consensus on all clients. And get the fee for that work.
  • Maintaining the private/public keys pairs, encoded in a keyfile, saved only in that client, the user is using. The keys are the ownership of Ether, and the identity in the contracts.
  • The DApps, ‘smart’ contracts, running on the Ethereum Virtual Machine, EVM, having states of the contracts stored together with the states of all accounts, saved on each client. Input/output of the contract’s functions are sent through the transactions on the blockchain. Transactions addressing contracts, are triggering the execution of them on the EVM.

The Ethereum Client is build to interact with network. As user interface, it has the directive line interface for the developer. API to the client exists as JSON RPC endpoints exposed on top of HTTP, WebSocket and/or IPC transports.

The Ethereum community has more then eight implementations of the Ethereum Client, see the list of clients. The most used are cpp-ethereum (C++), go-ethereum (Go) and pyethapp (Python).

The go-ethereum has the executable Geth, you access in the directive line interface. The Ethereum Client is embarked by typing Geth console, and you are given the interactive javascript environment in the guideline line, in comeback. Fastening a running client, type Geth fasten, and you are given the interactive javascript environment against this client in the directive line.

Developing DApss

Contracts are EVM bytecode programs, running on the EVM in the client. To develop contracts, you code them using one of the following language available: Solidity, Serpent or LLL. Solidity is the most common.

For the chosen language, you must install the compiler for the language. It is not included in the client. Then the compiled bytecode can be delivered to the client through the guideline line. There are more ways to compile the code, see Compiling a contract. If the directive line is used, you must give the source code in one line, and very first eliminate end-of-lines. Use remove-line-breaks.

You creates a contract on the blockchain by sending a transaction to an empty address with the EVM bytecode. The entire process using Geth guideline line is described in Contracts.

Ethereum Mist Wallet

In marts 2016, a fresh major version of Ethereum, named “Homestead”, was released. This release included the Ethereum Mist Wallet.

This Wallet is one big installation package, containing the go-ethereum client, the Solidity compiler and a entire fresh UI-application:

Download it from Install it and open it. Go after the instruction, choose the TEST-NET for development. And let it run syncronizing — downloading blocks — for about 10–20 min. When finished, you create the main account. Then it is recommended to begin mining. Find the menu item Commence Mining, under Develop. You will, within thirty min., have enough Ether — from TEST-NET — to be able to create your very first contract and other transaction, you want to send. It is only in the TEST-NET, it is so effortless to mine some Ethers. In the upper right corner you see the amount of Ether, the Wallet contains. You can create another account and send some Ether to that account as well. Then you have two account that can interact with your contracts.

Creating contract is very effortless, click on the CONTRACT ikon in the contraption bar, then click on Deploy… — and embark writing a contract. Examples, you can embark with:

The Ethereum Mist Wallet is a fine user app for the developer — for using the Ethereum blockchain, writing contracts and deploying them on the blockchain, sending transactions of any kind, watching contracts and showcasing latest transactions. It has a generic interface to accessing any contract and its functions.

But it is not an end-user application for other than IT-developers.

How to develop UI apps — in general?

When talking about an app, any webapp or mobile app, accessing the Ethereum Client, we are back on the guideline line and the API, using JSON RPC endpoints exposed on top of HTTP, WebSocket and/or IPC transports.

The interface language is Javascript in the interactive environment on instruction line. It is also Javascript in the Web3.js, which make life effortless in interfacing with the JSON RPC.

Makoto Inoue has made a movie tutorial about getting embarked with webapp interface to the Ethereum Client and using Web3. And he has made a github repo, where he has collected Web3.js with js-libs that it depends on, and a description on how to embark Geth and how to make it accessable as a ordinary webserver.

  • Clone the code
  • Run geth in testnet mode permitting rpc call from local port 8000
  • Startup web server at the port you specified at geth — rpccorsdomain. On Mac you can use python that is included in the OS X.
  • Open the page

The JSON RPC accessed through Web3.js is not recommended to be used over public internet, but only used as a local interface.

Ethereum’s examples shows how to use Web3.js in a html/javascript webapp.

Where is the iPhone in this context?

Apple’s native language Swift — nice language — and the older one, Objective-C — before Swift, you had to live with it — share the same runtime environment and are the development platform for all the apps known from Apple Store.

Apple’s iOS7 was the very first iOS version to officially support javascript as a mobile development language. It was part of the strategy of supporting the two development platforms:

  1. Native app: Swift/Objective-C platform
  2. Web app: HTML5/JavaScript platform

And they can both be included in the same app. Using the JavaScriptCore framework you are able to inject javascript from Swift or Objective-C programs within your native apps and get callbacks from the javascript directly into the Swift or Objective-C programs. It can be done in different ways, see the blog: javascriptcore-and-swift. As explained in the blog, the Webkit’s WKWebView is permitted to run javascript at full-speed, using the Safari-engine.

The solution is an app including JavaScriptCore using Web3.js against the Ethereum client, and use Apples native apps for the UI. And the JavaScriptCore framework must be running in a background thread within the app, just like normal internet-access should be treated. So the iPhone is always able to react to incoming phone-calls or react to common user interaction on the same app busy running interactions with the Ethereum in background.

The iPhone development setup

The development setup for this is:

This is not how the final solution should be. While we are waiting on the official Light Client to Ethereum, we can actually begin developing end-user apps through the development setup, using a Mac as bridge to the Ethereum network.

We can begin developing a real DApp having its own UI app designed for its contracts in Ethereum. Develop and deploy the contracts is done using Ethereum Mist Wallet. Developing the rest of it is done using the Xcode on Mac.

The coming Ethereum Light Client

The development setup will make sense, if we assume the following about the coming light client:

  • It will contain network routing, detect and maintain connections to other clients in the P2P Wire Protocol Network. The network must be switched to prepare for communication with Light Clients.
  • No blockchain database, but holding copy of own transactions, and holding status of own accounts.
  • No mining.
  • It will contain the private/public keys pairs, encoded in a keyfile, and the maintenance of them — for the users, using the Light Client.
  • No contracts, no Ethereum Virtual Machine, but able to send transactions against contracts in the network.

The coming Ethereum Light Client could look like this — in a iPhone context:

Here the Light Client is directly connected to the P2P Wire Protocol Network. Web3.js will be updated to be able to access a Light Client, and the UI + JS-core would hopefully be able continuing without major switches. Hopefully.

Related video:

Leave a Reply

Your email address will not be published. Required fields are marked *