SECRET OF CSS

Web 3.0 — Building Apps With the Slowest Database in the Universe | by Doug Foo | Aug, 2022


How using a blockchain as a general purpose database is the slowest, least scalable, least private, and most costly solution

0*g yS QVO1dyCYE0b
Photo by Braňo on Unsplash

Just in case it wasn’t clear:

  • Web 1.0 most people think of as HTML and data retrieval in the Netscape and HTML era (up until the late 90s)
  • Web 2.0 is evolving with JS/DHTML and modern dynamic frameworks like React.js.
  • Web 3.0 is building web apps using blockchain as the backend transaction and data store (driven by Etherium)
  • Web 4.0 is vaguely claimed to be the “Symbiotic Web”
  • Web 5.0 was mentioned by Jack Dorsey as a BTC-based version of Web 3

There are a few central ideas in Web 3.0, including the following:

  1. Using blockchains to store and process arbitrary data (e.g., Smart Contracts)
  2. Decentralizing the web with blockchain-based data storage, so a single entity does not wholly own data and platforms
  3. Using blockchain tender as the “equity” and “payment” medium for transactions, data storage, and site management — leading to the utopian state of decentralized control (DAO — Decentralized Autonomous Organizations)

Tying it together are a few pieces of tech like the web3 libraries in JavaScript, contract meta languages like Solidity, and browser-based coin wallets like MetaMask.

1*B6FZtdTi3ts1qZa309O7RA
Try it at http://web3.foostack.ai — code @ https://github.com/dougfoo/web3chat

I took a starter kit from DAPUniversity and rewrote bits of it to create my own Web3 App. The idea was for a new online chat service like Reddit:

  • People can post messages
  • People can like messages
  • People can reply to messages

I didn’t finish the third feature, but the first two required creating a new Smart Contract definition, figuring out how to compile and register it, then building the interface from the UI to the web3 APIs.

The tech stack was pretty simple:

  • ReactJS on the front end, using web3 libraries to operate blockchain contracts
  • MetaMask wallet to interact with blockchains and pay for contract writes
  • Ropsten tests ETH network to register and test the app for free
  • A few other tools like Truffle, Infurio, and Ganache for dev support

Writing the contract is pretty easy using Solidity. The code looks like any IDL to define an interface/contract. It may be a “Turing Complete language” (not a fan of abusing the fancy term), but its functionality is pretty primitive. You can store scalars and structures but can’t do simple things like iterate through a collection so easily.

1*OO RjIZZO4fjc7WTmKuXjQ
Original Chat contract and compiled ABI ready for deployment to ETH blockchain

Compiling and deploying can be done online with Remix or directly via Truffle, a developer toolchain.

1*0dKHCG70Ibqar iHLAzmNw
The online way with Remix — add your code and register your contract

Using Truffle is more streamlined but requires a bit more setup — linking your wallet to a blockchain node like Infura.io which means yet another system to create an account on (setup a node locally with Ganache). Once setup, you can compile, deploy and inspect and test the blockchain contracts using the Truffle CLI.

1*dT2GHVCTpVaGOFnj aICtg
Truffle console to inspect a few Chat messages

The web3 API in JavaScript lets you load the Chat contract and execute APIs to do things like finding, creating, and liking messages directly on a web page. Payment of a little ETH (gas) is required for each write transaction. Thus, linkage to the MetaMask wallet is needed.

The example above is pretty self-explanatory; it enables access to your ETH wallet (via MetaMask), gets a ref to the Chat contract, then allows direct API access to do reads like messageCount(), messages(id), and executes blockchain writes like createMessage(msg, id) and likeMessage(id).

Building this demo was fun, as is any hack development project intended just for learning (as opposed to production software where > 50% of the effort is error handling and testing). A few areas where I see problems are:

  1. Reading is really slow — just reading ten contract messages off the blockchain takes a few seconds.
  2. Writing is really slow — ETH is way faster than BTC, but it is still really slow. On Ropsten, it takes 5–10 seconds to increment the “like counter” on my contract object.
  3. Database scale — as my prior points convey, it is way too slow with ETH contract operations, so a significant infra is needed to build cache and performance layers on top of the raw blockchain.
  4. Transaction cost — every write costs ETH, which is fine for Ropstein because it’s free, but I can’t imagine paying real ETH every time a user writes something.
  5. No privacy — the great part about blockchain is transparency, but how do I ever write any private data, like if I wrote a P2P chat app? I suppose you can add your own encryption layer on top?
  6. Contract API is primitive — it seems cumbersome to find and iterate thru objects on the blockchain and imagine a more robust revision is needed to support indexing, fast hash lookups, etc.
  7. Toolchains are primitive — while I’m sure it has grown 500% in a year, it is quite a bit of Googling and hunting to understand how to connect Truffle to Infurio and what versions of tools to install.

I imagine the real applications won’t have client-side Web3 API calls and client-side wallets, but instead, Web3 app servers that manage your wallets and enable robust caching layers on top of the rudimentary blockchain APIs.

Web3 is an interesting merger of Web + Blockchains, but I doubt this is the sole evolution of the web — hence I’d prefer changing the name from Web 3.0 to something like Web 2.21b to avoid misleading the public.

1*khEzp4MGKK1Q3N123jZGmQ
Google search for “web 3.0”



News Credit

%d bloggers like this: