And the trials and tribulations thereof
Bitcoin grabbed our attention by providing anonymous, decentralized, and independently verifiable transactions using a currency that can’t be forged or destroyed.
As amazing as that was, the real killer app that bitcoin ushered in was the “Blockchain”. Smart folks quickly realized that an immutable, distributed, fault tolerant database that couldn’t be revised without leaving a clear audit trail opened the door to some fantastic opportunities.
Ethereum was designed to take better advantage of this powerful new database than Bitcoin had. Instead of simply recording transactions, the designers of Ethereum made a virtual machine and storage mechanism resulting in a “turing complete” machine, that was simple enough to suit fast peer to peer validation and confirmation of new transactions.
Introduction to the Project
How can we, in just a couple weeks, build a useful app on top of Ethereum?
The idea is straightforward; a smart contract that accepts a small payment of ether (or it could be expanded to other considerations of value; from bitcoin, to other currencies, or even more creative exchanges), and when the payment is confirmed the contract automatically releases the funds to the seller, and access to the content to the buyer. We called it TinyPay.
Thumbnail sketch of TinyPay
The basic workflow for clients of TinyPay looks like this:
- Sign up on our web app with the sellers domain name.
- Ask the seller to register a DNS record with a token we provide.
- Send an event from the contract once the domain is configured to trigger our “oracle” to perform a DNS check for the token.
- The oracle periodically checks the DNS record, and once the domain has been verified the oracle sends a follow up transaction to the contract, confirming that the domain is legitimate.
- Consumers of the sellers content see the prompt to make a micropayment, and if they choose to buy access to the content, then they click the payment button.
- A secure payment window pops up (currently using browser plugin MetaMask), prompting the user to confirm a small micro transaction of ether to the contract, from their configured Ethereum wallet.
- As soon as the payment is approved, the seller provides access to the content to the buyer. Funds are transferred quickly and irrevocably in seconds.
- A very small transaction fee is sent to the holder of the contract, and payment is released to the seller from the contract on behalf of the buyer.
Other high level languages you can use are Serpent (similar to Python), and LLL (Lisp Like Language, but closer to assembly). Serpent compiles down to LLL and direct use of LLL seems to be deprecated. In reality Solidity is quickly becoming the de-facto standard for writing Ethereum contracts.
In our TinyPay.co app, we want to verify ownership of the sellers domain, but that requires some DNS lookups that are not possible from the smart contract. Enter the “Oracle”, an application designed to conduit external data into the contract. We take a deeper look at Oracles and ours in particular in this follow up post.
Web app client (for third party sites)
When a buyer clicks our “buy now” button the web app client triggers the transaction process.
Web app sign up
The first aha! moment for me in developing against Ethereum was when I understood that running a blockchain node is essentially running a database replica. It keeps in sync with every other database replica across a peer to peer network (in this case thousands of nodes). Some useful and interesting features of the Ethereum “database” include immutability / append only updates, event emitting, and a form of eventual consistency based on consensus between peer nodes.
Consensus and transactions in general are a byproduct of the mining process that propagates the Ethereum blockchain. In Bitcoin, for example, the incentive for miners to expend resources on mining is that they can earn Bitcoin for each block they mine. Ethereum is similar, but there are additional incentives for miners; each transaction includes a (usually very small) fee that goes to the miners who process the transactions.
When building distributed apps, all your middleware and front end code can be written essentially as you normally would. To connect to the “database” back end, there are language bindings for most of the popular languages these days. (Go, .NET, node.js, Java, Python, Ruby, etc.) One thing to keep in mind is that Ethereum is under active development, and the client libraries are in various stages of completion.
Must Win would love to help develop your next “DApp”. If you’re looking for help understanding or utilizing block chain tech, reach out to email@example.com and reference this post.
John Weldon writes back-end code for various projects and has experience in a wide range of technologies and programming languages.