dApps: The experience is the same same but different…
Adventures in building a real-world dApp with KnownOrigin.io
Whether it is on your smart-phone or sat on your laptop we all interact with apps on a daily basis. Checking whether the train is late, booking your next holiday, viewing Kim Kardashian’s latest fashion choice, and even replying to that email from the boss.
dApps or decentralised applications are pretty much the same thing as apps with subtle differences. They generally have a user interface that looks familiar, they generally display information and let end-users submit data and see the corresponding response.
So what is actually different?
Blockchain. As a rule of thumb, dApps interact with a Blockchain in some way. Centralised apps will typically be backed by a database.
So what did it take to build a dApp?
Building
We had a web front end for KnownOrigin.io. Basically the same as a traditional web application, you still have HTML and JavaScript but you need to use a few additional tools.
We built on the Ethereum Blockchain so an additional dependency called Web3Js allows us to do funky cryptography stuff like sign transactions and read/write data directly from a Blockchain.
Smart contracts are where your logic on the Blockchain is held and executed. Writing these required knowledge of a proprietary language called Solidity. It’s a bit thorny but has many recognisable features. We used the excellent truffle framework to help smooth this process.
We stuck to a test-driven approach that we can’t recommend strongly enough as bugs can literally cost money in this eco-system.
In summary, you can use all your existing web development/full stack skills and blend in a few new tricks and you can develop dApps on a Blockchain. The journey might have a few speed bumps on the road but stick with it…where we are going they are no roads!
User Experience
Now this is where is gets interesting.
Now where do I login?
Answer: you don’t. In the brave new world of Blockchain your identity is your private & public key.
This is a bit weird at first, but it makes a lot of sense, we don’t want to manage a huge database of usernames and passwords. On the Blockchain identity can be derived from your public address that looks something like this: 0x3f8c962eb167ad2f80c72b5f933511ccdf0719d4
At KnownOrigin.io you don’t need to have a Blockchain identity to browse our digital artworks but you would require one to purchase an asset.
Thankfully extension tools like MetaMask make it easy enough for the average Joe to create accounts, fund them with cryptocurrency, and interact with the decentralised world. MetaMask always stores you private key (think password) within the browser making the whole thing secure.
Mobile Blockchain browsers, such as Trust Wallet, are another way to interact with dApps and they again incorporate account management and the ability to help build transactions.
Once you have used Ethereum enhanced browsers a few times it becomes a bit more natural but we admit this is a learning curve for new users.
The digital artwork is taking too long to load…
All of a sudden we are not reading from a local tuned Database so pulling data is suddenly slower than you would expect. On the KnownOrigin.io site we have added additional text to explain this but after years of a little bit of spinner and lots of nice data to consume the end-user has certain expectations. If these are not met — they may just give up 😒
We are thinking about caching solutions to make the site more responsive but this highlights that working in a decentralised manner brings new challenges.
I am not getting instant feedback on my purchase. What happened?
Blocks have to mined on a Blockchain to verify transactions. On Ethereum this can take from 10 seconds to several minutes or even worse depending on gas prices. It’s a dark art. We are adding more feedback to the purchase process but we are not working with a predictable local database. As soon as we can we provide a link to Etherscan to natively view the transaction (feels a bit disjointed). Once we know it has been confirmed we update the user interface. This is a UX work-in-progress for all involved with Blockchains. How do you best communicate this interaction. Answers on a postcard?
Deployment
So you have your contracts and code ready to go. What do I do to get some sweet ETH through my dApp?
How do I get my smart contract on a Blockchain?
At this point you need to understand once you deploy to the live chain the contract is immutable. KnownOrigin.io is deployed at 0xdde2d979e8d39bb8416eafcfc1758f3cab2c9c72 — we had to be extra certain we were happy with the code before we pulled the trigger once deployed it is tricky to change and upgrade (unlike traditional software).
How do I “mint” new assets or update the contract?
All of sudden instead of running a simple migration script or deploying a bug fix you now have to interact with the contract directly on the chain. This can be fiddly as you must have implemented the intended logic for change and be planning well in advance what might be required. Factor in getting gas prices and getting transactions onto the chain in a timely and cost-effective manner — all of sudden this is not as much fun as you thought it would be!
Summary
Blockchain development and creating dApps is building a new web 3.0 (that could change the face of the internet) but this technology is still in it’s infancy and needs skilled practitioners to understand the subtle differences from the well trodden software practices we know and love.
Be patient. Educate yourself and your end-users. Embrace the challenges and before you know it we will be all living in a decentralised world and logging on to a application will suddenly feel like sticking a DVD on.
Disclaimer: KnownOrigin.io holds application data in either a Blockchain or distributed file storage (IPFS) but the front-end is hosted traditionally on a web server (Firebase). Purists would argue that this should be hosted in a decentralised manner also.
To find out more about BlockRocket (who built the aforementioned dApp) follow @BlockRocketTech or get involved with our community group Blockchain Manchester at @blockchain_manc.
Visit KnownOrigin.io, join the telegram channel, or simply follow us on twitter @knownorigin_io for further updates on our progress.