> 2022年01月17日信息消化 ### Defining the web3 stack > MEMO > 目前自己在web3中感受到的最大的吸引力, 就是wallet带来的authentication与payment的便利性. > 去中心化/匿名等, 从户视角看还好... origin: [Defining the web3 stack](https://edgeandnode.com/blog/defining-the-web3-stack) When building a traditional web or mobile application, I often depend on a handful of building blocks to get the job done. 1. API / app servers (REST or GraphQL) 2. Authentication layer (managed or hand-rolled) 3. Database 4. Client-side frameworks, platforms, and libraries 5. File storage It turns out, the answer to this is not so straightforward because: 1. The paradigm is completely different in many ways 2. The web3 tools, technologies, and ecosystem are less mature than web2 #### What is web3? **Web3 is the stack of protocols that enable fully decentralized applications.** With this decentralized tech stack, we can begin building out decentralized applications which have their own set implications and characteristics. Some of the characteristics enabled by web3 are: - Decentralized web infrastructure - Ownership (of data, content, and platform) - Native digital payments - Self-sovereign identity - Distributed, trust-less, & robust infrastructure - Open, public, composable back ends Native digital payments and public back end infrastructure – like machine learning, mobile devices, virtual reality, and other technological primitives, platforms, and building blocks – enable entirely new types of applications to be built, some that have yet to be imagined. 原生数字支付和公共后端基础设施——如机器学习、移动设备、虚拟现实和其他技术原语、平台和构建块——能够构建全新类型的应用程序,其中一些应用程序尚未被想象。 Does this mean that everything is going to be replaced by web3? Not necessarily. While I do think that building on a decentralized tech stack is a much better choice for certain types of applications – like almost any technical decision, it depends on what you are building. Let’s now start diving into the web3 stack, broken into this set of categories: - Blockchain - Blockchain development environment - File storage - P2P Databases - API (Indexing & querying) - Identity - Client (frameworks and libraries) - Other protocols #### Blockchain One thing that is often important to me when learning something new is the idea of applying the [Pareto principle](https://en.wikipedia.org/wiki/Pareto_principle) to what I’m learning. i.e., **what is the most efficient way to get the most out of that amount of time and effort.** Following this idea I can gain the most traction and momentum while learning something new in the shortest amount of time. In the Blockchain world, learning Solidity and the [EVM](https://ethereum.org/en/developers/docs/evm/) (or Ethereum Virtual Machine) might be the best bet when getting started as a blockchain developer. Using this skillset (and tech stack), you can build not only for Ethereum, but other Ethereum Layer 2s, sidechains, and even other blockchains like Avalanche, Fantom, and Celo. ##### Blockchain development environments For EVM development, there are a few good development environments available: - [Hardhat](https://hardhat.org/) (JavaScript) is a newer option, but one that is gaining more and more popularity. Their docs are great, the tooling and developer experience is polished, and it’s what I’ve personally been using to build dapps. - [Truffle](https://trufflesuite.com/) (JavaScript) is a suite of tools for building and developing applications on the EVM. It’s mature, battle tested, and well documented. It’s been around for a while and many developers use it. - [Foundry](https://github.com/gakonst/foundry) is a new Solidity development environment from Paradigm that shows a lot of promise. Key standouts are the ability to write tests in Solidity, support for fuzzing, and speed (it's written in Rust). I wrote a separate introduction to it [here](https://mirror.xyz/sha.eth/6Mn3HjrqKLhHzu2balLPv4SqE5a-oEESl4ycpRkWFsc). - [Brownie](https://eth-brownie.readthedocs.io/en/stable/) is a Python-based development and testing framework for smart contracts for Solidity / EVM development. #### File Storage Where do we store images, videos, and other files in web3? Storing anything that large on-chain is usually prohibitively expensive, so we probably don’t want to store them there. Instead, we can use one of a handful of file storage protocols: - IPFS - peerto-peer file system protocol - pros: it’s reliable, well documented with a large ecosystem - cons: if data is not pinned it can be lost - [Arweave](https://arwiki.wiki/) - allows you to store data permanently, paying a single transaction fee. I’m a fan of Arweave and wrote a blog post about it [here](https://edgeandnode.com/blog/developers-guide-to-arweave). - [Filecoin](https://filecoin.io/) - from Protocol Labs, the same team that build IPFS, it is a protocol designed to provide a system of persistent data storage. There are [a handful of ways](https://docs.filecoin.io/store/) for developers to build on Filecoin, including [web3.storage](https://web3.storage/) which is pretty nice. - [Skynet](https://siasky.net/) - I have not yet used it in production, but have tried it out and it seems to work nicely. The API [here](https://siasky.net/developers) looks great. I have questions like how long is the data persisted, and Skynet's interoperability with other protocols. #### P2P Databases In addition to file storage and on-chain storage, you may also need to store data off-chain. You might use these types of solutions similarly to how you might use a database in a traditional tech stack, but instead they are replicated across n number of nodes on a decentralized network, and therefore more reliable (at least in theory). 除了文件存储和链上存储之外,您可能还需要在链下存储数据。您可能会使用这些类型的解决方案,就像您在传统技术堆栈中使用数据库的方式一样,但它们会在分散网络上的 n 个节点上复制,因此更可靠(至少在理论上)。 A few options are: - [Ceramic Network](https://ceramic.network/) - a decentralized, open source platform for creating, hosting, and sharing data. Ceramic also has a nice identity protocol that I’ll talk about later. Probably my favorite off-chain storage solution at the moment. [Here’s](https://twitter.com/ceramicnetwork/status/1364631929262235648) a pretty nice demo. - Textile [ThreadDB](https://docs.textile.io/threads/) - a multi-party database built on IPFS and Libp2p. If I understand correctly, it may be going through a big API change at the moment. I’ve tried it and it shows some promise, but the docs and DX need some improvement. - [GunDB](https://gun.eco/) - a decentralized, peer-to-peer database. Gun has been around for quite sometime and [some pretty interesting applications](https://www.starlinglab.org/challenges/) have been built with it. #### API (Indexing & Querying) There are a lot of differences in the way that we interact with and build on top of blockchains versus databases in the traditional tech stack. With blockchains, data isn’t stored in a format that can efficiently or easily be consumed directly from other applications or front ends. 我们在区块链上进行交互和构建的方式与传统技术堆栈中的数据库存在很多差异。使用区块链,数据不会以可以直接从其他应用程序或前端有效或轻松使用的格式存储。 Blockchains are optimized for write operations. You often hear the innovation happening centered around transactions per second, block time, and transaction cost. Blockchain data is written in blocks over the course of time, making anything other than basic read operations impossible. 区块链针对写入操作进行了优化。您经常听到围绕每秒交易量、区块时间和交易成本发生的创新。区块链数据随着时间的推移以块的形式写入,使得除了基本读取操作之外的任何操作都是不可能的。 In most applications, you need features like relational data, sorting, filtering, full text search, pagination and many other types of querying capabilities. In order to do this, data needs to be indexed and organized for efficient retrieval. 在大多数应用程序中,您需要关系数据、排序、过滤、全文搜索、分页和许多其他类型的查询功能等功能。为此,需要对数据进行索引和组织以进行有效检索。 Traditionally, that’s the work that databases do in the centralized tech stack, but that indexing layer was missing in the web3 stack. [The Graph](https://thegraph.com/en/) is a protocol for indexing and querying blockchain data that makes this process much easier and offers a decentralized solution for doing so. Anyone can build and publish open GraphQL APIs, called subgraphs, making blockchain data easy to query. #### Identity Identity is a completely different paradigm in web3. In web2, authentication is almost always based on a user’s personal information. This information is usually gathered either via a form or an OAuth provider that asks the user to hand over in exchange for access to the application. 身份是 web3 中完全不同的范式。在 web2 中,身份验证几乎总是基于用户的个人信息。此信息通常通过表单或 OAuth 提供程序收集,该提供程序要求用户交出以换取对应用程序的访问。 In web3, identity revolves completely around the idea of wallets and [public key cryptography](https://blog.mycrypto.com/the-basics-of-public-key-cryptography). 在 web3 中,身份完全围绕钱包和公钥密码学的概念展开。 While the name “wallet” serves its purpose, I’ve found that people new to web3 find the terminology confusing as it relates to authentication and identity. I hope that in the future we can figure out some other way to convey what a wallet is, as it combines aspects of finance but also identity and reputation. 虽然“钱包”这个名称有其目的,但我发现 web3 的新手会发现这个术语与身份验证和身份相关而令人困惑。我希望将来我们能找到其他方式来传达钱包是什么,因为它结合了金融方面,还结合了身份和声誉。 As a developer, you will need to understand how to access and interact with the user’s wallet and address in various ways. At a very basic level (and a very common requirement), you might want to request access to the user’s wallet. To do this, you’ll usually be able to access the user’s wallet in the window context (web browser) or using something like [WalletConnect](https://walletconnect.com/) or [Solana’s Wallet Adapter](https://github.com/solana-labs/wallet-adapter). 在一个非常基本的级别(也是一个非常常见的要求),您可能想要请求访问用户的钱包。为此,您通常可以在窗口上下文(Web 浏览器)中访问用户的钱包,或者使用 WalletConnect 或 Solana 的 Wallet Adapter 之类的东西。 If you want to handle authentication yourself, you can allow the user to sign a transaction and then decode it somewhere to authenticate the user, but this usually requires a server. [Here](https://mirror.xyz/sha.eth/i6ry1Mxez53z91ef375sMe2rO1NvK2ipACyzKA4SR9g) is an example of how that might look using an EVM wallet, and [here](https://docs.phantom.app/integrating/sending-a-transaction#signing-and-sending-a-transaction) is an example of how to do this with Solana / Phantom. 如果您想自己处理身份验证,您可以允许用户签署交易,然后在某处对其进行解码以对用户进行身份验证,但这通常需要服务器。这是使用 EVM 钱包的示例,以及如何使用 Solana / Phantom 执行此操作的示例。 What about managing user profiles in a decentralized way? [Ceramic Network](https://developers.ceramic.network/learn/welcome/) offers the most robust protocol and suite of tools for managing decentralized identity. They recently released [a blog post](https://blog.ceramic.network/the-next-architecture-for-building-web3-data-applications/) outlining some of their most recent updates and giving some guidelines around how all of the tools work together. I’d start there and then explore [their docs](https://developers.ceramic.network/learn/welcome/) to gain an understanding of how to start building, and consider checking out my example project [here](https://github.com/dabit3/decentralized-identity-example) that uses Ceramic [self.id](https://developers.ceramic.network/tools/self-id/overview/). If you want to fetch a user’s [ENS](https://docs.ens.domains/) text records, the [`ensjs`](https://github.com/ensdomains/ensjs) library offers a nice API for fetching user data: ```javascript const ens = new ENS({ provider, ensAddress: getEnsAddress('1') }) const content = await ens.name('sha.eth').getText('avatar') ``` [SpruceID](https://spruceid.com/) is also something that looks promising but I’ve yet to try it out. #### Client As far as JavaScript frameworks go, you can really build with anything you’d like, as the client-side blockchain SDKs are mostly framework-agnostic. That being said, an overwhelming number of projects and examples are built in React. There are also a handful of libraries like [Solana Wallet Adapter](https://github.com/solana-labs/wallet-adapter) that offer additional utilities for React, so I’d say that learning or being familiar with React is going to probably be a smart move. 就 JavaScript 框架而言,你真的可以用你想要的任何东西来构建,因为客户端区块链 SDK 大多与框架无关。话虽如此,绝大多数项目和示例都是用 React 构建的。还有一些像 Solana Wallet Adapter 这样的库为 React 提供了额外的实用程序,所以我想说学习或熟悉 React 可能是一个明智的举动。 For client-side SDKs in Ethereum there’s [web3.js](https://web3js.readthedocs.io/en/v1.5.2/) and [ethers.js](https://docs.ethers.io/v5/). To me Ethers is more approachable and has better documentation, though web3.js has been around longer. In Solana, you’ll probably be working with [@solana/web3.js](https://docs.solana.com/developing/clients/javascript-api) and / or [Anchor](https://project-serum.github.io/anchor/getting-started/introduction.html). I’ve found Anchor client libraries to be my go-to for building Solana programs since I’m using Anchor framework anyway, and I’ve found it much easier to understand then `@solana/web3.js`. #### Other protocols [Radicle](https://radicle.xyz/) is a decentralized code collaboration protocol built on Git. It could be thought of as a decentralized version of GitHub. [Livepeer](https://livepeer.org/) is a decentralized video streaming network. It is mature and widely used with over 70,000 GPUs live on the network. [Chainlink](https://chain.link/) is an Oracle that enables access to real-world data and off-chain computation while maintaining the security and reliability guarantees inherent to blockchain technology. ### Misc - [Tech Giants’ Billion-Dollar Acquisitions](https://www.cbinsights.com/research/tech-giants-billion-dollar-acquisitions-infographic/?utm_source=CB+Insights+Newsletter&utm_medium=email&utm_campaign=newsletter_general_wed_2022_01_19&utm_term=block-3&utm_content=research-public) -  - [The 4 Identities of a Teacher](https://every.to/praxis/the-4-identities-of-a-teacher-reporter-expert-mentor-role-model) - Reporter, Expert, Mentor, Role Model - "What we learn from history is that no one learns from history." ― Otto von Bismarck | [reddit](https://www.reddit.com/r/quotes/comments/s2lfsl/what_we_learn_from_history_is_that_no_one_learns/) - [The Future of the Modern Data Stack in 2022](https://towardsdatascience.com/the-future-of-the-modern-data-stack-in-2022-4f4c91bb778f) - Data Mesh: It’s a design concept with some wonderful concepts like distributed ownership, domain-based design, data discoverability, and data product shipping standards — all of which are worth trying to operationalize in your organization. > So here’s my advice: As data leaders, it is important to stick to the first principles at a conceptual level, rather than buy into the hype that you’ll inevitably see in the market soon. - Metrics Layer: It’s been called the **metrics layer**, **metrics store**, **headless BI**, and even more names than I can list here. - Reverse ETL: I’m pretty excited about everything that’s solving the “last mile” problem in the modern data stack. We’re now talking more about how to use data in daily operations than how to warehouse it. - Active Metadata & Third-Gen Data Catalogs - Data Teams as Product Teams - Data Observability: the idea of “monitoring, tracking, and triaging of incidents to prevent downtime” — came in. - [Your CSS reset needs text-size-adjust (probably)](https://kilianvalkhof.com/2022/css-html/your-css-reset-needs-text-size-adjust-probably/?ref=sidebar) ```css *, *:before, *:after { box-sizing: inherit; margin: 0; padding: 0; } :root { box-sizing: border-box; text-size-adjust: none; -webkit-text-size-adjust: none; position: relative; font-family: system-ui, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; min-height: 100%; } body { position: relative; height: 100%; min-height: 100vh; font-size: 100%; line-height: 1.5; } input, textarea, button { font-size: inherit; font-family: inherit; } ```