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 r3cev.com/blog/2016/Five/29
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).
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 github.com. 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.
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.
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.
- Native app: Swift/Objective-C platform
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.