<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: danielAsaboro</title>
    <description>The latest articles on Forem by danielAsaboro (@danielasaboro).</description>
    <link>https://forem.com/danielasaboro</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1083124%2F29a59607-4f9e-4fb3-8042-4975b0b5951d.png</url>
      <title>Forem: danielAsaboro</title>
      <link>https://forem.com/danielasaboro</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/danielasaboro"/>
    <language>en</language>
    <item>
      <title>Accounts: The Digital DNA of Solana</title>
      <dc:creator>danielAsaboro</dc:creator>
      <pubDate>Sun, 15 Dec 2024 10:08:00 +0000</pubDate>
      <link>https://forem.com/danielasaboro/accounts-the-digital-dna-of-solana-3nli</link>
      <guid>https://forem.com/danielasaboro/accounts-the-digital-dna-of-solana-3nli</guid>
      <description>&lt;p&gt;In 1953, James Watson burst into a Cambridge pub and declared "We have discovered the secret of life!" He and Francis Crick had just unveiled &lt;a href="https://www.nature.com/scitable/topicpage/discovery-of-dna-structure-and-function-watson-397/" rel="noopener noreferrer"&gt;DNA's double helix&lt;/a&gt; - a four-letter code that orchestrates all living things, from bacteria to blue whales. What made their discovery so profound wasn't just mapping life's blueprint, but revealing how something so simple could create such boundless complexity.&lt;/p&gt;

&lt;p&gt;History has shown us that the most revolutionary systems often emerge from radical simplification. Unix transformed computing by declaring that "&lt;a href="https://en.wikipedia.org/wiki/Everything_is_a_file#:~:text=%22Everything%20is%20a%20file%22%20is,through%20the%20filesystem%20name%20space." rel="noopener noreferrer"&gt;everything is a file&lt;/a&gt;". This reduced complex hardware interactions to simple read and write operations. A programmer could now command a printer, read from a keyboard, or access network packets using the same basic commands.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.lego.com/en-us/history/articles/d-the-stud-and-tube-principle?locale=en-us" rel="noopener noreferrer"&gt;LEGO built an empire&lt;/a&gt; on this same insight. Their standardized studs and tubes - identical plastic blocks - enable children to construct everything from medieval castles to space stations. Similarly, the Internet thrives on a simple foundation: &lt;a href="https://en.wikipedia.org/wiki/Network_packet" rel="noopener noreferrer"&gt;&lt;strong&gt;packets&lt;/strong&gt;&lt;/a&gt; - a universal protocol that breaks all digital communication into simple, standardized units. This foundational simplicity enables seamless global connectivity, whether streaming video or sending emails.&lt;/p&gt;

&lt;p&gt;Even art follows this pattern. &lt;a href="https://johnmjennings.com/all-music-is-made-from-just-12-notes/" rel="noopener noreferrer"&gt;Music's infinite variety springs from just 12 notes&lt;/a&gt; in the chromatic scale, spawning countless genres across centuries and cultures. Modern computing relies on &lt;a href="https://en.wikipedia.org/wiki/Logic_gate" rel="noopener noreferrer"&gt;basic logic gates&lt;/a&gt; - "AND," "OR," and "NOT" - yet these simple operations power everything from calculators to artificial intelligence.&lt;/p&gt;

&lt;p&gt;These systems - spanning science, technology, toys, networks, and art - may seem vastly different on the surface but they reveal a crucial insight: &lt;strong&gt;when we find the right elemental building block, transformation follows&lt;/strong&gt;. True simplicity isn't a constraint - it's the foundation for boundless possibilities.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solana embodies this same powerful principle
&lt;/h2&gt;

&lt;p&gt;It radically declared that "everything is an account."&lt;/p&gt;

&lt;p&gt;Just as DNA's four nucleotides can encode all of life's complexity, Solana's unified account structure serves as the universal building block for every transaction, program, and piece of data on the network. This isn't just an architectural choice; it's the key to understanding how Solana achieves its remarkable speed and scalability.&lt;/p&gt;

&lt;p&gt;To be fair, when I first started developing on the Solana Blockchain, this concept felt alien. Coming from traditional development, I expected different data structures for different purposes - one type for storing data, another for programs, and yet another for user wallets. But Solana challenged this assumption entirely.&lt;/p&gt;

&lt;p&gt;Make no mistake though, this uniformity isn't limiting - it's liberating. Let me show you how…&lt;/p&gt;

&lt;h2&gt;
  
  
  The Anatomy of an Account
&lt;/h2&gt;

&lt;p&gt;Just as every DNA strand shares the same basic structure of nucleotides arranged along a sugar-phosphate backbone, every Solana account has fundamental properties that define its structure:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvwr76xg5isxczhokb39l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvwr76xg5isxczhokb39l.png" alt="Diagram showing the fundamental structure of a Solana account. A blue-bordered rectangular container displays six key properties: Address (32 bytes), Balance (in SOL/lamports), Data (program-specific information), Owner (program that can modify data), Size (allocated space), and Executable flag (true/false). Each property is shown in a light blue box with bold labels." width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;An address (32 bytes, like DNA's position on a chromosome)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A balance in SOL (like cellular resources)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Data (like genetic information)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;An owner (a program that can modify the account's data, similar to gene regulatory systems)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Size (amount of space allocated)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Executable flag (whether it contains program code)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Rent settings (rent exemption)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Account Types: Different Genes, Same DNA
&lt;/h2&gt;

&lt;p&gt;Like how different genes serve different functions while using the same genetic code, Solana accounts take on specialized roles through different configurations:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgb8oe6e43ptqjk9rp4by.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgb8oe6e43ptqjk9rp4by.png" alt="Comparison diagram of three Solana account types arranged horizontally. Left: Program Accounts (blue) showing executable code properties. Center: Data Accounts (green) showing data storage capabilities. Right: Token Accounts (orange) showing token-related features. Each type includes specific characteristics and an iconic representation. Connected by a dashed line labeled 'Unified Account Structure' at the bottom." width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  a) Program Accounts
&lt;/h3&gt;

&lt;p&gt;Think of these as the enzyme-producing genes of Solana. They store executable code that can process instructions and modify other accounts. Just as enzymes catalyze specific biological reactions, program accounts execute specific on-chain operations. The System Program, for instance, is like a housekeeping gene, managing fundamental operations like account creation and SOL transfers.&lt;/p&gt;

&lt;h3&gt;
  
  
  b) Data Accounts
&lt;/h3&gt;

&lt;p&gt;These are like the vast stretches of regulatory DNA that store critical information. Data accounts can hold any arbitrary data: marketplace listings, game states, social media posts, or governance proposals. Just as regulatory DNA controls when and how genes are expressed, data accounts often control program behavior.&lt;/p&gt;

&lt;h3&gt;
  
  
  c) Token Accounts
&lt;/h3&gt;

&lt;p&gt;Consider these the protein-coding genes of the Solana ecosystem. They store information about token ownership and balances. Just as proteins have specific shapes and functions, token accounts have standardized structures (defined by the SPL Token Program) that enable fungible and non-fungible token operations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Advanced Account Patterns
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fldnc6kll7e1jth08pyi5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fldnc6kll7e1jth08pyi5.png" alt="Split-panel diagram comparing DNA control systems with Solana account patterns. Left panel (pink) shows DNA mechanisms: transcription factors binding to DNA strands and protein synthesis from DNA sequences. Right panel (blue) shows Solana equivalents: multi-signature authorization with circular signature indicators, and account derivation showing seed input leading to PDA output. The parallel layouts emphasize how biological and digital systems use similar control patterns." width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  a) Signer Accounts and Authorization
&lt;/h3&gt;

&lt;p&gt;Just as DNA has mechanisms to control gene expression, Solana has sophisticated systems for controlling account access. Signer accounts act like transcription factors, providing necessary authorization for specific operations. This creates a natural security model where complex operations require multiple specific "signatures," similar to how complex biological processes often require multiple regulatory proteins.&lt;/p&gt;

&lt;h3&gt;
  
  
  b) Account Seeds and Derivation
&lt;/h3&gt;

&lt;p&gt;The concept of account seeds in Solana parallels how DNA sequences can be used to predict protein structures. Just as specific DNA sequences reliably produce specific proteins, account seeds can deterministically generate specific addresses. This enables powerful patterns like Program Derived Addresses (PDAs), where accounts can be predictably located without requiring private keys.&lt;/p&gt;

&lt;h2&gt;
  
  
  Account Interactions: The Cellular Symphony
&lt;/h2&gt;

&lt;p&gt;Biology emerges from countless molecular interactions orchestrated by DNA, and Solana's power similarly comes from how accounts interact.&lt;/p&gt;

&lt;p&gt;When a transaction arrives, it triggers a cascade of interactions reminiscent of cellular signaling pathways. Program accounts, like cellular enzymes, execute their code on data accounts, which serve as both substrates and products of these computational reactions. Token accounts participate in this dance by transferring assets between parties, much like proteins shuttling molecules between cellular compartments.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxlvdz6vghqlcjib6n8sq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxlvdz6vghqlcjib6n8sq.png" alt="Sequence diagram showing interaction between Client, Program A, Program B, Program C, Data Account, and Token Account. Arrows indicate the flow of calls and returns, with notes comparing the process to biochemical cascades. Shows how programs can call other programs and interact with various account types." width="784" height="449"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Cross-Program Composition
&lt;/h3&gt;

&lt;p&gt;The real magic happens in cross-program composition. Programs can call other programs, creating complex chains of execution similar to biochemical cascades. This composability enables rich applications to emerge from simple account interactions, just as complex biological systems emerge from simple molecular mechanisms.&lt;/p&gt;

&lt;h3&gt;
  
  
  Transaction Processing and Parallelization
&lt;/h3&gt;

&lt;p&gt;Like cellular machinery processing multiple genes simultaneously, Solana's runtime can process multiple transactions in parallel. This is made possible by the unified account structure, which allows the runtime to easily identify independent operations. The result is a system that can achieve remarkable throughput while maintaining consistency.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj8fkz7nhdwkzwx1wp836.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj8fkz7nhdwkzwx1wp836.png" alt="Three-tier flowchart showing Solana transaction processing. Top tier: 'Incoming Transactions' showing three parallel transaction boxes. Middle tier: 'Parallel Processing' with two lanes showing independent transaction processing and account state management. Bottom tier: 'Program Execution' displaying three program boxes (A, B, C) with interconnecting arrows showing the flow between tiers." width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Cost of Digital Existence
&lt;/h2&gt;

&lt;p&gt;Just as cells require energy to maintain their DNA and molecular machinery, accounts in Solana must pay for their existence through a mechanism called "rent."&lt;/p&gt;

&lt;p&gt;This storage fee, paid in lamports (fractional SOL), scales with the account's size - larger accounts require more resources, just as more complex cellular structures demand more energy to maintain.&lt;/p&gt;

&lt;h3&gt;
  
  
  Rent Economics and Network Health
&lt;/h3&gt;

&lt;p&gt;The rent system isn't merely a pricing mechanism; it's fundamental to the network's health. Accounts can become exempt from rent by maintaining a minimum balance, similar to how cells maintain energy reserves for essential functions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwsshqz89rbfnq9cbp1ya.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwsshqz89rbfnq9cbp1ya.png" alt="Two-panel visualization of Solana's rent system. Left panel: Graph showing exponential relationship between account size (x-axis) and rent cost (y-axis) with a blue curve. Right panel: Account lifecycle stages with circular nodes connected by arrows, showing creation, maintenance, and deletion phases." width="800" height="393"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Those that can't maintain this balance face deletion, allowing Solana to reclaim their space - a process remarkably similar to how biological systems break down and recycle defunct cells and damaged DNA. This digital metabolism ensures network resources are used efficiently, with inactive accounts naturally falling away while vital ones persist.&lt;/p&gt;

&lt;h2&gt;
  
  
  Security Through Simplicity
&lt;/h2&gt;

&lt;p&gt;The standardization of accounts creates a robust security model. Like how DNA repair mechanisms can identify and fix damaged sequences, Solana's runtime can easily verify account modifications against consistent rules. This uniformity makes it harder to introduce vulnerabilities through edge cases or unexpected interactions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frww3erzylqx8eu41fl29.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frww3erzylqx8eu41fl29.png" alt="Split-panel diagram comparing security mechanisms in DNA and Solana systems. Left panel (pink) shows DNA safety: repair processes detecting and fixing errors in DNA strands, and checkpoint verification for state transitions. Right panel (blue) shows Solana safety: standardized account verification with multiple checkmarks, and controlled state transitions between validated states. The parallel structures emphasize how both systems use standardization for security." width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Memory Safety and Runtime Guarantees
&lt;/h3&gt;

&lt;p&gt;The unified account structure enables strong runtime guarantees about memory safety and state transitions. Just as cellular machinery ensures DNA is correctly replicated and expressed, Solana's runtime ensures accounts are accessed and modified according to strict rules. This creates a predictable and verifiable system of state transitions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Building the Future: Development Patterns
&lt;/h2&gt;

&lt;p&gt;Understanding accounts as Solana's DNA opens new possibilities for protocol design. When designing a new protocol, the question becomes not "what different types of structures do I need?" but rather "how can I arrange these universal building blocks to create the functionality I want?" It's like being a genetic engineer, but instead of genes, you're working with accounts.&lt;/p&gt;

&lt;p&gt;This paradigm shift fundamentally changes how we approach blockchain development. Just as genetic engineers don't invent new types of nucleotides but rather arrange existing DNA building blocks in novel ways, Solana developers work with a consistent set of account primitives to create complex systems.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faurzgmhhnocyw15bfeib.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faurzgmhhnocyw15bfeib.png" alt="Diagram comparing traditional vs account-centric development approaches. Left panel shows traditional development with separate boxes for custom data types, specialized storage, and complex infrastructure. Right panel shows account-centric development with a unified account structure at top and interconnected boxes below showing data flow and permissions. A blue arrow labeled 'Paradigm Shift' connects the two approaches, illustrating the transition in thinking. The entire diagram emphasizes the movement from complexity to unified simplicity." width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Account Engineering Mindset requires a fundamental shift in thinking - away from creating custom types and specialized storage solutions, towards thinking in terms of accounts and their relationships. This account-centric approach means carefully considering data flows, permissions, and component interactions through account relationships.&lt;/p&gt;

&lt;h3&gt;
  
  
  The most elegant Solana programs emerge through composition over complexity.
&lt;/h3&gt;

&lt;p&gt;Rather than building specialized structures, experienced developers combine existing account patterns in novel ways, breaking down complex requirements into simpler account interactions that compose together - much like how complex biological systems emerge from chains of simple chemical reactions.&lt;/p&gt;

&lt;p&gt;When designing Solana programs, developers must consider both account economics and lifecycles. Each account carries real costs in network resources, demanding efficient designs that minimize size while maximizing utility. Well-designed programs include mechanisms for cleaning up unused accounts and reclaiming resources, just as biological systems recycle cellular components.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg1dyyq0srpfmuyb030vh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg1dyyq0srpfmuyb030vh.png" alt="Split-panel comparison diagram showing the parallel evolution of complexity in DNA and Solana systems. Left panel (pink) shows DNA progression: from basic nucleotides, through genes and regulatory elements, to complete organisms. Right panel (blue) shows Solana progression: from unified account structure, through programs and account patterns, to decentralized applications. Connected by arrows showing progression from simple to complex, with title 'Building Complex Systems from Simple Primitives' and bottom text emphasizing how complexity emerges from simple components." width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Nature's use of DNA as a universal format enables remarkable efficiency, security, and adaptability.
&lt;/h3&gt;

&lt;p&gt;Solana's unified account structure provides similar benefits - there's no need for complex routing between different types since all components speak the same language through unified accounts.&lt;/p&gt;

&lt;p&gt;The beauty of Solana's design, like DNA itself, lies in how unlimited complexity emerges from elegant simplicity. By embracing this universal structure, developers create sophisticated systems while maintaining the security and performance benefits of standardization.&lt;/p&gt;

&lt;p&gt;This is the profound insight at Solana's core: just as life's endless variety emerges from four simple nucleotides, the future of decentralized computing can emerge from the elegant simplicity of unified accounts.&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>web3</category>
      <category>cryptocurrency</category>
      <category>solana</category>
    </item>
    <item>
      <title>Welcome to Solana: A Web2 Developer's Travel Guide to the Blockchain Nation</title>
      <dc:creator>danielAsaboro</dc:creator>
      <pubDate>Sat, 14 Dec 2024 09:55:46 +0000</pubDate>
      <link>https://forem.com/danielasaboro/welcome-to-solana-a-web2-developers-travel-guide-to-the-blockchain-nation-ipc</link>
      <guid>https://forem.com/danielasaboro/welcome-to-solana-a-web2-developers-travel-guide-to-the-blockchain-nation-ipc</guid>
      <description>&lt;p&gt;"Papers, please!"&lt;/p&gt;

&lt;p&gt;It's a phrase that makes even the most seasoned traveller's heart skip a beat. Standing at border control, passport in hand, you're about to enter a new country.&lt;/p&gt;

&lt;p&gt;Every nation has its own rules, its own culture, its own way of doing things. Some stamp your passport with intricate designs, others scan your biometrics, and a few might even ask you to sing their national anthem (looking at you, Bhutan).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Entering the world of Solana blockchain feels remarkably similar.&lt;/strong&gt; And just like a modern country, it has its own customs, its own "official language," and yes - its own rather particular way of checking your papers. But don't worry; unlike that nerve-wracking moment at immigration, I'll be your friendly local guide.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Personal Note
&lt;/h2&gt;

&lt;p&gt;Three months ago, I was that bewildered tourist, staring at Solana terms like PDAs and SPL tokens the way most people stare at visa requirements written in bureaucratese. Now, after countless hours of exploration (and more than a few wrong turns), I'm ready to be your guide through this fascinating blockchain nation.&lt;/p&gt;

&lt;p&gt;In this guide, we'll explore Solana not as a mere blockchain protocol, but as a thriving digital nation. We'll walk through its carefully designed institutions (built-in programs), understand its unique governance model (consensus mechanism), and learn how its citizens (accounts) interact within its borders. Think of this as your comprehensive citizenship guide – everything you need to know to become a productive member of the Solana ecosystem.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;p&gt;Want to explore a specific aspect of our digital nation? Feel free to use this guide to jump directly to any section that interests you. Whether you're curious about setting up your digital passport (wallet), understanding our national currency (SOL), or exploring our economic zones (DeFi), each section is designed to be independently accessible while still connecting to the broader narrative.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The Immigration Process (Getting Started)&lt;/li&gt;
&lt;li&gt;The Government Structure (Built-in Programs)&lt;/li&gt;
&lt;li&gt;The National Infrastructure &amp;amp; Constitution&lt;/li&gt;
&lt;li&gt;Citizens and Their Laws (Accounts &amp;amp; Smart Contracts)&lt;/li&gt;
&lt;li&gt;Local Customs &amp;amp; Public Works (Programming &amp;amp; Runtime)&lt;/li&gt;
&lt;li&gt;International Relations (Cross-Chain Communication)&lt;/li&gt;
&lt;li&gt;The Economic Zones (DeFi and dApps)&lt;/li&gt;
&lt;li&gt;Emergency Services (Security Features)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Immigration Process (Getting Started)
&lt;/h2&gt;

&lt;p&gt;Like any journey to a new country, your first steps in Solana require some paperwork. Here's what you'll need:&lt;/p&gt;

&lt;h3&gt;
  
  
  Your Digital Passport (Wallet)
&lt;/h3&gt;

&lt;p&gt;Picture yourself at a futuristic spaceport. Instead of a leather-bound booklet with stamps, your passport here is entirely digital - we call it a &lt;code&gt;wallet&lt;/code&gt;. But this isn't your average digital billfold. Like the retinal scanners and fingerprint readers of modern airports, your Solana wallet contains sophisticated cryptographic credentials that prove you belong in this digital nation.&lt;/p&gt;

&lt;p&gt;At its heart are three critical components, each playing a vital role in your identity. They are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Private Key&lt;/li&gt;
&lt;li&gt;Public Key&lt;/li&gt;
&lt;li&gt;SeedPhrase&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fznhape8hy43y4m8pzuzr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fznhape8hy43y4m8pzuzr.png" alt="Image description" width="800" height="487"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Think of your &lt;code&gt;public key&lt;/code&gt; as your cosmic address - a unique identifier that lets others find and interact with you across the vastness of the blockchain. It's like having your own personal QR code that anyone can scan to send you messages or assets.&lt;/p&gt;

&lt;p&gt;Your &lt;code&gt;private key?&lt;/code&gt; That's your digital DNA - an absolutely unique signature that proves you are who you claim to be. Guard it as carefully as you would the keys to your house, because in this digital realm, possession of the private key literally makes you... you.&lt;/p&gt;

&lt;p&gt;And then there's the &lt;code&gt;seed phrase&lt;/code&gt; - your ultimate backup plan. Imagine if you could distill your entire identity into twelve simple words. That's exactly what a seed phrase does. It's like having a magical incantation that can recreate your entire digital presence if everything else is lost. Store it somewhere fireproof, waterproof, and definitely not in a text file labeled "crypto stuff."&lt;/p&gt;

&lt;h2&gt;
  
  
  The National Currency (SOL)
&lt;/h2&gt;

&lt;p&gt;Every nation has its currency, but SOL is no ordinary money. Welcome to the economy of tomorrow, where currency transcends simple transactions to become the lifeblood of an entire digital ecosystem.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyg93imsex7jsncdqrsr4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyg93imsex7jsncdqrsr4.png" alt="Image description" width="800" height="512"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Think of SOL as a Swiss Army knife of finance - a tool that transforms based on how you use it.&lt;/p&gt;

&lt;p&gt;When you're shopping in the digital bazaars of Solana, SOL works just like traditional money - a medium of exchange for buying NFTs, trading tokens, or investing in new projects. But that's just its most basic function.&lt;/p&gt;

&lt;p&gt;Need to run a program or execute a smart contract? SOL becomes your computing currency. It's like paying for electricity or water in the physical world - a necessary resource that powers the nation's infrastructure. Each transaction, each program execution, requires a tiny amount of SOL, ensuring the network stays efficient and spam-free.&lt;/p&gt;

&lt;h3&gt;
  
  
  SOL's most fascinating role might be in governance.
&lt;/h3&gt;

&lt;p&gt;Through staking, your SOL becomes like a government bond and voting right rolled into one. By staking your tokens, you're not just earning returns - you're helping secure the network and having a say in its future.&lt;/p&gt;

&lt;p&gt;And then there's rent - a unique concept in the Solana nation. Just as you pay rent for physical storage, accounts on Solana require SOL to maintain their space on the blockchain. It's like paying for your digital real estate, ensuring efficient use of network resources.&lt;/p&gt;

&lt;p&gt;Think of it this way: If the Solana network is a thriving digital city, SOL isn't just its currency - it's the fuel that keeps its engines running, the votes that guide its future, and the resource that maintains its infrastructure. In this digital nation, your SOL is your stake in the entire ecosystem.&lt;/p&gt;

&lt;h3&gt;
  
  
  Residency Papers (Account Creation)
&lt;/h3&gt;

&lt;p&gt;In Solana, establishing residency means creating accounts. Unlike traditional countries where you might have one residency permit, Solana citizens often maintain multiple accounts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Base Account: Your primary residence&lt;/li&gt;
&lt;li&gt;Program-Derived Accounts (PDAs): Government-assigned addresses for specific purposes&lt;/li&gt;
&lt;li&gt;Token Accounts: Like having different bank accounts for different currencies&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Government Structure (Built-in Programs)
&lt;/h2&gt;

&lt;p&gt;Every nation needs its core government services. In Solana, these come in the form of built-in programs. Unlike others, Solana's bureaucracy runs with algorithmic precision. Imagine a government where every department operates 24/7, processes requests in milliseconds, and never makes you wait in line. Welcome to Solana's built-in programs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuyejp2t3x1u5nn10jf36.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuyejp2t3x1u5nn10jf36.png" alt="Image description" width="800" height="455"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The Department of Treasury (System Program)
&lt;/h3&gt;

&lt;p&gt;At the heart of our digital nation sits the System Program - think of it as a combination of the Treasury Department and the Department of Interior. It's the bedrock institution that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Handles the fundamentals of citizenship&lt;/li&gt;
&lt;li&gt;Creates new accounts with mathematical precision&lt;/li&gt;
&lt;li&gt;Manages the flow of SOL throughout the ecosystem&lt;/li&gt;
&lt;li&gt;Ensures every transaction follows the rules&lt;/li&gt;
&lt;li&gt;Maintains the very infrastructure that makes our digital nation possible&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The Central Bank (Token Program)
&lt;/h3&gt;

&lt;p&gt;Down the street from the Treasury, you'll find our version of the Federal Reserve - the Token Program. But unlike traditional central banks, this one can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mint new types of currencies (tokens) with just a few lines of code&lt;/li&gt;
&lt;li&gt;Process thousands of transfers per second without breaking a sweat&lt;/li&gt;
&lt;li&gt;Maintain perfect records of every token ever created or moved
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// A glimpse at how our Central Bank operates:&lt;/span&gt;
&lt;span class="nx"&gt;TokenProgram&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;transfer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;fromAccount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;toAccount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The Department of State (Associated Token Program)
&lt;/h3&gt;

&lt;p&gt;Think of this as our foreign relations office, but with a twist. The Associated Token Program standardizes how citizens interact with different types of tokens. It's like having a universal translator for digital assets. It creates predictable addresses for token accounts and makes sure your assets are always exactly where you expect them to be.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Electoral Commission (Stake Program)
&lt;/h3&gt;

&lt;p&gt;Finally, we have our unique take on democratic participation. The Stake Program manages the network's security through economic incentives:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🗳️ Citizens can stake their SOL to become active participants in network security&lt;/li&gt;
&lt;li&gt;💼 Validators are chosen based on their stake, ensuring skin in the game&lt;/li&gt;
&lt;li&gt;🔒 The whole system runs automatically, with rewards and slashing happening in real-time&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The National Infrastructure &amp;amp; Constitution
&lt;/h2&gt;

&lt;p&gt;Picture a vast metropolis stretching across digital space. But unlike any city you've known, this one runs on pure mathematics and consensus. At its heart beats a revolutionary innovation: Solana's Proof of History (PoH).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fingz51uqlu1gwtc1pcln.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fingz51uqlu1gwtc1pcln.png" alt="Image description" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The Cities (Nodes)
&lt;/h3&gt;

&lt;p&gt;If Solana is a country, its nodes are its cities – bustling hubs of activity that never sleep. In these digital metropolises:&lt;/p&gt;

&lt;p&gt;• Validator nodes stand like gleaming skyscrapers, processing thousands of transactions per second. Each one is a combination courthouse and record office, validating transactions and maintaining the official ledger.&lt;/p&gt;

&lt;p&gt;• Between them, RPC nodes act as neighborhood information kiosks, helping regular citizens like us interact with the network. They're the friendly faces of our digital bureaucracy.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Universal Clock (Proof of History)
&lt;/h3&gt;

&lt;p&gt;What truly sets Solana apart is its revolutionary traffic system. Imagine trying to coordinate a global flash mob without being able to agree on what time it is. That's the problem most blockchains face. Solana solved this with an ingenious solution: a blockchain with its own built-in clock.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Think of PoH as a cosmic metronome:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Every event gets its own timestamp&lt;/span&gt;
&lt;span class="n"&gt;event1&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;hash&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;event2&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;hash&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;event3&lt;/span&gt;
&lt;span class="c1"&gt;// Creating a verifiable sequence of time&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The Results? They're staggering:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;400 millisecond block times&lt;/li&gt;
&lt;li&gt;Up to 65,000 transactions per second&lt;/li&gt;
&lt;li&gt;A throughput that would make an NYSE trader's head spin&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The Constitution (Consensus)
&lt;/h3&gt;

&lt;p&gt;But a fast clock alone isn't enough – you need everyone to agree on the rules. That's where Solana's consensus mechanism comes in. It's like having:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🏛️ A supreme court that rules on transactions in milliseconds&lt;/li&gt;
&lt;li&gt;🤝 A system where everyone agrees on "what happened when"&lt;/li&gt;
&lt;li&gt;⚡ The speed of dictatorship with the fairness of democracy&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Citizens and Their Laws (Accounts &amp;amp; Smart Contracts)
&lt;/h2&gt;

&lt;p&gt;In our digital nation, citizenship takes on fascinating new forms. Every account is both a citizen and a piece of property, each with its own unique rights and capabilities.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Citizens (Accounts)
&lt;/h3&gt;

&lt;p&gt;Walk down any street in Solana, and you'll meet three types of digital citizens:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Program Accounts&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Data Accounts&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Native Accounts&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh9gmbazcujf3v2yj6jsz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh9gmbazcujf3v2yj6jsz.png" alt="Image description" width="800" height="529"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's take a brief overview:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Program Accounts&lt;/strong&gt; - Our civil servants, tirelessly executing code 24/7. Unlike human bureaucrats, they never take coffee breaks or call in sick. Each one contains executable code that follows its instructions with perfect precision.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Data Accounts&lt;/strong&gt; - Think of these as the homes and businesses of our digital nation. They store everything from personal balances to complex financial instruments. Like real estate in the physical world, they require rent to maintain their space on the blockchain.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Native Accounts&lt;/strong&gt; - The special institutions that keep our nation running, like the SOL mint. They're built into the very fabric of Solana, as fundamental as a country's central bank or supreme court.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  The Laws (Smart Contracts)
&lt;/h3&gt;

&lt;p&gt;Here's where things actually get really interesting.&lt;/p&gt;

&lt;p&gt;Unlike traditional contracts that require courts and lawyers to enforce, smart contracts are self-executing pieces of code. It's like having:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Traffic laws that make it physically impossible to speed&lt;/li&gt;
&lt;li&gt;Business agreements that settle instantly without dispute&lt;/li&gt;
&lt;li&gt;Property transfers that complete the moment conditions are met
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Laws that enforce themselves&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;TokenContract&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;transfer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Account&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Account&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="c1"&gt;// Transfer happens automatically&lt;/span&gt;
            &lt;span class="c1"&gt;// No lawyers needed&lt;/span&gt;
            &lt;span class="c1"&gt;// No courts required&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When Alice sends Bob 5 SOL, there's no bank to approve the transfer, no clearing house to process it, and no way for the transaction to fail if Alice has the funds. The code simply... executes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The real magic is in what this enables.&lt;/strong&gt; These self-enforcing laws create an environment where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Trust is built into the mathematics&lt;/li&gt;
&lt;li&gt;Agreements execute with computer precision&lt;/li&gt;
&lt;li&gt;Innovation can flourish without bureaucratic overhead&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Local Customs &amp;amp; Public Works (Programming &amp;amp; Runtime)
&lt;/h2&gt;

&lt;p&gt;Every nation develops its own way of doing things, its own customs and practices that make it unique. In Solana, this manifests in both its programming culture and its public infrastructure.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Local Languages
&lt;/h3&gt;

&lt;p&gt;While Rust remains the "official language" of Solana - like Mandarin in China - our digital nation has become increasingly polyglot. Through tools like Poseidon, developers can now write smart contracts in familiar TypeScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Modern Solana development&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyContract&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;initialize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;State&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Signer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Write code as naturally as breathing&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Think of it as having universal translators - write in the language you know best, and Poseidon translates it into high-performance Rust code that Solana understands natively.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Public Infrastructure
&lt;/h3&gt;

&lt;p&gt;But a nation needs more than just languages - it needs robust infrastructure. Solana's runtime is built like a city's utility system, but with some crucial differences:&lt;/p&gt;

&lt;h3&gt;
  
  
  The Transit System
&lt;/h3&gt;

&lt;p&gt;Imagine a subway that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Never stops running (400ms block times)&lt;/li&gt;
&lt;li&gt;Gets faster as more people use it (parallel processing)&lt;/li&gt;
&lt;li&gt;Automatically routes around congestion (Gulf Stream)
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Every transaction flows through optimized channels&lt;/span&gt;
&lt;span class="n"&gt;transaction&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;mempool&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;validator&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;block&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The Utility Grid
&lt;/h3&gt;

&lt;p&gt;Just as cities charge for electricity and water, Solana has its own utility model:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🏠 &lt;code&gt;Rent&lt;/code&gt; - Pay for the space your accounts occupy&lt;/li&gt;
&lt;li&gt;💡 &lt;code&gt;Compute Units&lt;/code&gt; - Like electricity for your programs&lt;/li&gt;
&lt;li&gt;🌊 &lt;code&gt;Memory&lt;/code&gt; - A flowing river of temporary storage&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here's the clever part: Just as you can prepay your utilities, Solana allows for "&lt;code&gt;rent exemption&lt;/code&gt;" - a one-time payment that maintains your account forever. It's like buying your piece of the blockchain outright.&lt;/p&gt;

&lt;h2&gt;
  
  
  International Relations (Cross-Chain Communication)
&lt;/h2&gt;

&lt;p&gt;Just as no modern nation exists in isolation, Solana maintains a vibrant network of diplomatic relations with other blockchain ecosystems. These relationships are facilitated through a sophisticated infrastructure of bridges and protocols, each serving a unique purpose in the grand scheme of cross-chain communication.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F60i8almd2ar4gl9wukx4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F60i8almd2ar4gl9wukx4.png" alt="Image description" width="800" height="536"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Embassies and Consulates (Bridges)
&lt;/h3&gt;

&lt;p&gt;Imagine Wormhole as the main international airport of Solana, a bustling hub where assets and data from other chains arrive and depart in a constant flow. It's a portal through which the citizens of Solana can access the wider multiverse of blockchain technologies, and through which denizens of other chains can experience the speed and efficiency of Solana.&lt;/p&gt;

&lt;p&gt;If Wormhole is the airport, then Portal Bridge is the secure customs checkpoint. It ensures that all incoming assets and data are scrutinized and verified, maintaining the integrity and security of Solana's native environment. Like a vigilant border guard, Portal Bridge stands watch over the flow of cross-chain traffic.&lt;/p&gt;

&lt;p&gt;For those who prefer a more grounded mode of transport, Allbridge serves as Solana's international rail system. It provides a stable, reliable connection to other chains, facilitating the steady flow of assets and information across blockchain borders.&lt;/p&gt;

&lt;h3&gt;
  
  
  Trade Agreements (Protocols)
&lt;/h3&gt;

&lt;p&gt;However, infrastructure alone does not make for successful international relations. Just as nations forge trade agreements and treaties, Solana engages in a variety of protocols to facilitate cross-chain interaction.&lt;/p&gt;

&lt;p&gt;These include mechanisms for cross-chain asset transfers, allowing the seamless movement of tokens and NFTs between Solana and its blockchain neighbours.&lt;/p&gt;

&lt;p&gt;Moreover, Solana participates in protocols for international data communication, ensuring that important information can be shared securely and efficiently across chain boundaries. In the spirit of global cooperation, Solana also engages in collaborative security measures, working with other chains to maintain the safety and integrity of the broader blockchain ecosystem.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Economic Zones (DeFi and dApps)
&lt;/h2&gt;

&lt;p&gt;Every thriving nation needs a robust economy. Welcome to the bustling marketplace of the future! If Solana is a digital nation, then its DeFi protocols and dApps are the vibrant bazaars and gleaming shopping districts where the real action happens.&lt;/p&gt;

&lt;p&gt;Down Protocol Plaza... Stroll past Raydium's bustling trading floors, where millions in digital assets change hands every hour. Next door, Marinade Finance's validators work their magic, turning staked SOL into liquid assets faster than a barista makes your morning coffee.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg5s0n6pshz08pekeof2v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg5s0n6pshz08pekeof2v.png" alt="Image description" width="800" height="536"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  In the Lending District:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Solend's smart contracts stand like modern banks but without the marble columns and stuffy loan officers&lt;/li&gt;
&lt;li&gt;Port Finance offers sophisticated financial instruments that would make Wall Street jealous&lt;/li&gt;
&lt;li&gt;And Oxygen Protocol runs its automated market maker with the precision of a Swiss watch&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The Digital Arts District
&lt;/h3&gt;

&lt;p&gt;Picture galleries floating in digital space, where art, music, and culture blend seamlessly with commerce. Here's what you might see on any given day:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🎨 Magic Eden's sprawling marketplace: Where digital artists showcase their latest creations And collectors bid in real-time auctions&lt;/li&gt;
&lt;li&gt;🎮 Star Atlas's massive gaming complex: Thousands of players piloting virtual spaceships Building entire economies in the digital void&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Social Squares
&lt;/h3&gt;

&lt;p&gt;And then there's the social heart of our digital city - platforms where communities gather, share, and create together:&lt;/p&gt;

&lt;p&gt;• Squads Protocol hosting decentralized team workspaces&lt;br&gt;
• Dialect enabling real-time messaging between wallets&lt;br&gt;
• GenesysGo provides the infrastructure that keeps it all connected&lt;/p&gt;
&lt;h2&gt;
  
  
  Emergency Services (Security Features)
&lt;/h2&gt;

&lt;p&gt;Every nation needs to protect its citizens. Ever wondered what keeps a digital nation safe? While there are no police cars with flashing lights in Solana, its security system is far more sophisticated - and never sleeps.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv1qgfifnqy4ex4fpq9p0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv1qgfifnqy4ex4fpq9p0.png" alt="Image description" width="800" height="536"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  The Digital Defense Force
&lt;/h3&gt;

&lt;p&gt;Picture a security system that combines the best of Fort Knox's physical security with the precision of a quantum computer. Solana's validators stand guard 24/7, each one running sophisticated algorithms that would make a cryptographer's head spin.&lt;/p&gt;
&lt;h3&gt;
  
  
  Critical Security Checkpoints:
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Every transaction must pass through multiple layers of verification&lt;/span&gt;
&lt;span class="n"&gt;transaction&lt;/span&gt;
    &lt;span class="nf"&gt;.verify_signatures&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;       &lt;span class="c1"&gt;// Like checking multiple forms of ID&lt;/span&gt;
    &lt;span class="nf"&gt;.verify_account_keys&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;     &lt;span class="c1"&gt;// Making sure you are who you say you are&lt;/span&gt;
    &lt;span class="nf"&gt;.verify_program_access&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;   &lt;span class="c1"&gt;// Confirming you have proper clearance&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Your Personal Security Detail:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Multi-signature capabilities act like having multiple keys to a vault&lt;/li&gt;
&lt;li&gt;Program authorization ensures that only approved code runs&lt;/li&gt;
&lt;li&gt;Account permissions let you control exactly who can do what&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  The Safety Net System
&lt;/h3&gt;

&lt;p&gt;Like any well-designed infrastructure, Solana has built-in circuit breakers and recovery systems. When issues arise, multiple systems spring into action:&lt;/p&gt;
&lt;h3&gt;
  
  
  a) Error Logging
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Detailed Transaction Traces&lt;/strong&gt;: Pinpoint problem sources.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Enable Quick Fixes&lt;/strong&gt;: Facilitate efficient debugging.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  b) Recovery Protocols
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Automatic State Rollbacks&lt;/strong&gt;: Maintain consistency during failures.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Transaction Retry Mechanisms&lt;/strong&gt;: Ensure operation continuity.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Graceful Error Handling&lt;/strong&gt;: Minimize disruption and improve user experience.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Think of it as having both airbags and seat belts - multiple layers of protection working together to keep your digital assets safe.&lt;/p&gt;
&lt;h2&gt;
  
  
  You've just completed your orientation tour
&lt;/h2&gt;

&lt;p&gt;From Solana's high-speed highways of transactions to its secure vaults of digital assets. But like any new citizen, your journey is just beginning.&lt;/p&gt;

&lt;p&gt;Picture yourself standing at the edge of a digital frontier. Behind you lies the familiar territory of traditional development. Ahead stretches an endless landscape of possibility, where smart contracts dance with decentralized applications, and every new block brings fresh opportunities.&lt;/p&gt;
&lt;h3&gt;
  
  
  What's Next On Your Journey?
&lt;/h3&gt;

&lt;p&gt;In our next guide, we'll roll up our sleeves and build something real. No more metaphors about digital countries - we're going to write actual code. Think of it as your first business venture in this new land, starting with a simple but powerful smart contract.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// A peek at what we'll build:&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyFirstContract&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="nx"&gt;PROGRAM_ID&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Pubkey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;...&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="nf"&gt;initialize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ContractState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Signer&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;Result&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Your first steps into Solana development&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Remember&lt;/strong&gt;: Every master builder in Solana started exactly where you are now. They were once a tourist in a new technology. The key isn't to understand everything at once, I didn't – Still don't. But you must keep building, one block at a time - That's how you get better.&lt;/p&gt;

&lt;p&gt;Until our next meeting, keep exploring. Ask questions in the Solana Discord. Try out different wallets. Maybe even deploy your first test program. Because in this digital nation, curiosity isn't just welcomed - it's the currency of innovation.&lt;/p&gt;

&lt;p&gt;See you on-chain! 🚀&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>solana</category>
      <category>web3</category>
      <category>cryptocurrency</category>
    </item>
    <item>
      <title>Web3 explained for Web2 Developers: My Personal Journey from SQL to Solana</title>
      <dc:creator>danielAsaboro</dc:creator>
      <pubDate>Fri, 13 Dec 2024 17:24:30 +0000</pubDate>
      <link>https://forem.com/danielasaboro/web3-explained-for-web2-developers-my-personal-journey-from-sql-to-solana-3jgm</link>
      <guid>https://forem.com/danielasaboro/web3-explained-for-web2-developers-my-personal-journey-from-sql-to-solana-3jgm</guid>
      <description>&lt;p&gt;I used to roll my eyes at blockchain. Really, I did. Every time someone mentioned "crypto" or "Web3," I'd mentally file it away in my "crypto-bro hype" folder and move on. But something strange happened during my late-night coding sessions this September.&lt;/p&gt;

&lt;p&gt;You know those moments when curiosity gets the better of you? Maybe it was the third cup of coffee, boredom, or perhaps it was watching one too many of my respected peers dive into this space. Whatever it was, I decided to peek under the hood. Just a quick look, I told myself. Three months later, I found myself excitedly whiteboarding blockchain concepts for my bewildered team members at 11 PM.&lt;/p&gt;

&lt;p&gt;These lessons have been invaluable in solidifying my understanding, and now I want to share this knowledge with you. This article is my attempt to do so.&lt;/p&gt;

&lt;p&gt;Let me start this story where we're all comfortable...&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding Blockchain Through Familiar Territory
&lt;/h2&gt;

&lt;p&gt;Every developer's story starts with databases. Remember your first &lt;code&gt;SELECT * FROM users&lt;/code&gt;? That moment when everything clicked and databases suddenly made sense? Or perhaps you're like me, and it was MongoDB's findOne() that made you fall in love with data storage.&lt;/p&gt;

&lt;p&gt;We all have our go-to systems—PostgreSQL, MariaDB, Cassandra—trusted companions that never let us down when it comes to storing, retrieving, and updating data. They're reliable, efficient, and feel like old friends.&lt;/p&gt;

&lt;p&gt;Here's the intriguing part: these traditional databases, as familiar as they are, represent just one way to think about data—how we store it, how we access it, and what we do with it. Blockchains aren't in any way different, they just approach data in a way that challenges conventional thinking.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe3xhf2fp18ilr0en54jx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe3xhf2fp18ilr0en54jx.png" alt="Blockchain vs Traditional Database" width="800" height="432"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's when my perspective started to expand, and the possibilities became endless.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Problem with Traditional Storage
&lt;/h2&gt;

&lt;p&gt;Do you know what really got me thinking? I kept running into the same wall with different projects, each time thinking "&lt;em&gt;There has to be a better way.&lt;/em&gt;"&lt;/p&gt;

&lt;p&gt;First, it was a voting system I tried building for a local organization. PostgreSQL, robust authentication, audit logs - the works. But when the client asked, "&lt;em&gt;How can voters be absolutely certain their votes weren't changed after the fact?&lt;/em&gt;" I sat there, coffee getting cold, realizing that "&lt;em&gt;just trust our admin team&lt;/em&gt;" wasn't going to cut it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fromgk8fil1a6mdbfcr89.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fromgk8fil1a6mdbfcr89.png" alt="Trust Issues" width="800" height="432"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Despite all our security measures, there was always this uncomfortable truth: someone with database access could technically alter the votes. No amount of authentication or audit logs could completely eliminate that risk.&lt;/p&gt;

&lt;h3&gt;
  
  
  Take my friend's recent project
&lt;/h3&gt;

&lt;p&gt;It's a &lt;a href="https://www.fool.com/investing/stock-market/market-sectors/financials/non-fungible-tokens/digital-collectibles/" rel="noopener noreferrer"&gt;digital collectibles&lt;/a&gt; marketplace built on MongoDB.&lt;/p&gt;

&lt;p&gt;Sounds straightforward, right? But when users started asking questions like "&lt;em&gt;How do I know you won't duplicate my rare items?&lt;/em&gt;" or "&lt;em&gt;What happens to my assets if your company goes under?&lt;/em&gt;", the limitations became painfully obvious. Every answer started with "&lt;em&gt;You'll have to trust that we...&lt;/em&gt;"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;And then there were the practical headaches:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Need to prove a record hasn't been modified? Better build a complex audit system.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Want to let users verify their own data? Hope you enjoy maintaining API documentation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Trying to create a truly peer-to-peer system? Good luck with those distributed database headaches.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How do you respond to "What happens to my assets if your company goes under"? "How can I prove I own the original if you control the database?"&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Even a seemingly simple loyalty points system for a chain of restaurants exposed these limitations. Customers wanted to trade points with each other, but preventing double-spending without a central authority? That's when I started seeing these trust issues everywhere.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe3l5uwxv4uefkrb75fff.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe3l5uwxv4uefkrb75fff.png" alt="Trust Issues Everywhere" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Every answer began with that same uncomfortable phrase: "&lt;em&gt;You'll have to trust that we...&lt;/em&gt;" Every "secure" system I'd built was secure only because someone - an admin, a company, a cloud provider - said it was. And in most cases, that was fine. But what about when it wasn't?&lt;/p&gt;

&lt;h2&gt;
  
  
  That's when Bitcoin's whitepaper started making a whole lot more sense...
&lt;/h2&gt;

&lt;p&gt;I still remember the exact moment Bitcoin clicked for me. It wasn't about cryptocurrency at all - it was about something far more profound. Picture this: It's 2008, and someone using the pseudonym Satoshi Nakamoto asks what seems like an impossible question: "&lt;a href="https://bitcoin.org/bitcoin.pdf" rel="noopener noreferrer"&gt;What if we could create a database that nobody owns, but everyone can trust?&lt;/a&gt;"&lt;/p&gt;

&lt;p&gt;At first, I thought, "Yeah, right. Good luck with that." But then I dug deeper, and that's when its elegance hit me. Think about what happens when you send money through your bank. You're trusting them to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Make sure you actually have the money&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Take it from your account&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Put it in someone else's account&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Not mess up anywhere along the way&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now, imagine doing all that without the bank. Sounds impossible, right? That's exactly what made Bitcoin brilliant. Instead of one bank checking the books, you've got thousands of computers worldwide all verifying transactions together. It's like having an entire stadium of accountants checking your math - try sneaking a bogus transaction past that!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgao3sc2ag5iyym2j0lfh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgao3sc2ag5iyym2j0lfh.png" alt="Bitcoin Network" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But here's what really made me sit up at 2 AM, spilling my coffee: &lt;strong&gt;Bitcoin solved the&lt;/strong&gt; &lt;a href="https://www.investopedia.com/terms/d/doublespending.asp" rel="noopener noreferrer"&gt;"double-spend"&lt;/a&gt; &lt;strong&gt;problem&lt;/strong&gt;. In plain English, it made it impossible to use the same digital money twice. That might not sound impressive until you realize no one had ever figured out how to do that without a central authority watching everything.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Ethereum Plot Twist
&lt;/h3&gt;

&lt;p&gt;Just when I thought I understood blockchain, Ethereum showed up and flipped my world again. See, Bitcoin was like a really good calculator - fantastic at one thing (moving money), but that was about it. Ethereum? That was like going from a calculator to a smartphone.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Smart Contract Revolution
&lt;/h2&gt;

&lt;p&gt;Here's what blew my mind about Ethereum: imagine writing code that, once deployed, runs exactly as written. No servers to crash. No admins to pull the plug. No company that could go bankrupt and take your service down. Coming from traditional backend development, this concept hit me like a ton of bricks.&lt;/p&gt;

&lt;p&gt;These "smart contracts" (terrible name, by the way - they're neither smart nor contracts) are like backend code with superpowers. Every time I deploy a regular API, there's this nagging thought: "What if AWS goes down? What if someone hacks the server? What if the database corrupts?" But with Ethereum's smart contracts? Once they're out there, they just... run. Forever. Exactly as written.&lt;/p&gt;

&lt;p&gt;But there was a catch (isn't there always?). Ethereum was like trying to run a modern app on a calculator - slow and expensive. Imagine &lt;a href="https://www.reddit.com/r/CryptoCurrency/comments/139y7z8/ethereum_gas_fees_are_too_damn_high/" rel="noopener noreferrer"&gt;paying $50 in gas fees just to store a tweet-sized piece of data&lt;/a&gt;. That's when Solana entered the chat.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Solana Speed Demon
&lt;/h2&gt;

&lt;p&gt;Picture this: I'm sitting there, frustrated with Ethereum's molasses-like 15 transactions per second, when I discover Solana. At first, I thought the numbers were a typo. Thousands of transactions per second? At fractions of a penny? It was like watching the first SSD after years of working with hard drives.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnv3gblm9kidrafuqj6qz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnv3gblm9kidrafuqj6qz.png" alt="Solana Speed" width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solana brought something called&lt;/strong&gt; &lt;a href="https://solana.com/news/proof-of-history" rel="noopener noreferrer"&gt;&lt;strong&gt;Proof of History (PoH)&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;to the table.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Think of it as a blockchain with a built-in clock. Instead of all the computers having to constantly agree on what time it is (which is what slows down other blockchains), &lt;a href="https://solana.com/validators" rel="noopener noreferrer"&gt;Solana's nodes&lt;/a&gt; can just get on with their work. It's elegant. It's fast. And most importantly, it actually makes sense for real-world applications.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F31o7q87u7uz9vk39alj9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F31o7q87u7uz9vk39alj9.png" alt="Solana Architecture" width="800" height="835"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why This Matters for Developers
&lt;/h2&gt;

&lt;p&gt;You know what's funny? After all the technical deep dives, my biggest revelation was almost embarrassingly simple: &lt;strong&gt;the blockchain is just a database with attitude&lt;/strong&gt;. We're not learning entirely new concepts - we're just looking at data storage through a different lens.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Think about it:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Instead of SELECT queries, we have read operations anyone can perform&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Instead of INSERT statements, we have transactions that get verified by the network&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Instead of database administrators, we have consensus mechanisms&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Instead of access control lists, we have cryptographic signatures&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The beauty of blockchain isn't in its complexity – it's in its simplicity. It's just a different type of database with unique properties: no central authority needed, impossible to tamper with data, code runs exactly as written, and anyone can verify what's happening.&lt;/p&gt;

&lt;p&gt;You already know how to code. You already understand databases. Blockchain is just the next step in that evolution – a database that belongs to everyone and no one at the same time.&lt;/p&gt;

&lt;h3&gt;
  
  
  Here's what really got me excited:
&lt;/h3&gt;

&lt;p&gt;TypeScript.&lt;/p&gt;

&lt;p&gt;Yes, you read that right. Not Solidity, not Rust, but good old TypeScript. Thanks to a framework called &lt;a href="http://poseidon.turbin3.com/usage.html" rel="noopener noreferrer"&gt;Poseidon (a collaboration between Solana Foundation and Turbine)&lt;/a&gt;, we can bring everything we love about Web2 development - type safety, familiar syntax, awesome tooling - into the Web3 world.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Future is Closer Than You Think
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkp9o4t36j8mjt74qt73o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkp9o4t36j8mjt74qt73o.png" alt="Future of Web3" width="800" height="418"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I'll be honest - three months ago, if you'd told me I'd be building blockchain applications in TypeScript, I would've laughed. But here I am, excited to share this journey with you. In the upcoming series, we'll dive into:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Setting up a Solana development environment (it's easier than you think)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Writing our first smart contract (in TypeScript!)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Understanding Solana's programming model (it's actually quite elegant)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Building real-world applications (yes, actually useful ones)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You don't need to be a cryptography expert. You don't need to understand every detail of consensus mechanisms. You just need to be curious and willing to look at problems differently.&lt;/p&gt;

&lt;p&gt;I hope this series of articles will help you realize that understanding blockchain isn't about learning entirely new concepts—it's about applying what we already know in a new context. So, it doesn't matter if you're a seasoned SQL developer or NoSQL enthusiast—your skills are transferable, and the journey to Web3 is shorter than you think.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Remember&lt;/strong&gt;: every senior developer you know was once a beginner at something. Three months ago, I was rolling my eyes at Web3. Now? I can't wait to show you what's possible.&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>web3</category>
      <category>solana</category>
      <category>database</category>
    </item>
    <item>
      <title>StateNotifierProvider: How to link your stateNotifier to your UI Widgets</title>
      <dc:creator>danielAsaboro</dc:creator>
      <pubDate>Fri, 10 Nov 2023 06:41:04 +0000</pubDate>
      <link>https://forem.com/danielasaboro/statenotifierprovider-how-to-link-your-statenotifier-to-your-ui-widgets-5bno</link>
      <guid>https://forem.com/danielasaboro/statenotifierprovider-how-to-link-your-statenotifier-to-your-ui-widgets-5bno</guid>
      <description>&lt;p&gt;In the previous post, we created our custom StateNotifier class by extending the StateNotifier class. However, the state changes weren't in any way linked to our Widgets/UI code.&lt;/p&gt;

&lt;p&gt;I also hinted that it's the job of a special type of Provider (the  StateNotifierProvider) to do that linking for us. It's similar to how a FutureProvider or StreamProvider links the result of a Future or Stream to the UI.&lt;/p&gt;

&lt;h2&gt;
  
  
  In summary:
&lt;/h2&gt;

&lt;p&gt;• Future =&amp;gt; FutureProvider&lt;br&gt;
• Stream =&amp;gt; StreamProvider&lt;br&gt;
• StateNotifier =&amp;gt; StateNotifierProvider&lt;/p&gt;

&lt;p&gt;That cleared, let's see how to do it.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Create a StateNotifierProvider
&lt;/h2&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;


&lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;cartProvider&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;StateNotifierProvider&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;CartNotifier&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Cart&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;((&lt;/span&gt;&lt;span class="n"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;CartNotifier&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;That looks like a mouthful.&lt;/p&gt;

&lt;h3&gt;
  
  
  So let's break it down.
&lt;/h3&gt;

&lt;p&gt;StateNotifierProvider is a class or type provided by Riverpod that allows you to create a provider for managing the application state. It requires two generic type parameters:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The user-defined StateNotifier type created by extending StateNotifier&lt;/li&gt;
&lt;li&gt;The State type that the Provider will hold. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In our case, it's &lt;code&gt;&amp;lt;CartNotifier, Cart&amp;gt;&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;In addition to what was said earlier, the CartNotifier is also responsible for managing the provider's state. While the Cart represents the data structure that the CartNotifier will manage.&lt;/p&gt;

&lt;h3&gt;
  
  
  StateNotifierProvider is an anonymous function
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;


&lt;span class="n"&gt;StateNotifierProvider&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;CartNotifier&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;It takes a reference to ref as a parameter, which is used to access other providers or perform side effects within the provider initialization.&lt;/p&gt;

&lt;p&gt;Then it creates an instance of the CartNotifier class, which we already said is responsible for managing the provider's state. You can also call a StateNotifierProvider a Constructor Function (a special function that creates and initializes an object instance of a class) for this reason.&lt;/p&gt;

&lt;h3&gt;
  
  
  In summary
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
 dart

final cartProvider = StateNotifierProvider&amp;lt;CartNotifier, Cart&amp;gt;((ref) {
  return CartNotifier();
});


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The block of code above creates a Riverpod provider named cartProvider that uses a &lt;strong&gt;&lt;em&gt;CartNotifier&lt;/em&gt;&lt;/strong&gt; to manage the state of type &lt;strong&gt;&lt;em&gt;Cart&lt;/em&gt;&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;When you access &lt;strong&gt;&lt;em&gt;cartProvider&lt;/em&gt;&lt;/strong&gt; in your code, it will provide the current state of &lt;strong&gt;&lt;em&gt;Cart&lt;/em&gt;&lt;/strong&gt; managed by the &lt;strong&gt;&lt;em&gt;CartNotifier&lt;/em&gt;&lt;/strong&gt;. &lt;/p&gt;

&lt;h2&gt;
  
  
  2. Use ref.watch() to read and continuously listen to the state Changes in your UI
&lt;/h2&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;


&lt;span class="c1"&gt;// Preceding code body removed for brevity&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;EachProductWidget&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="n"&gt;ConsumerWidget&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;Product&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;EachProductWidget&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="kd"&gt;required&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;product&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="kd"&gt;required&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="nd"&gt;@override&lt;/span&gt;
  &lt;span class="n"&gt;Widget&lt;/span&gt; &lt;span class="n"&gt;build&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BuildContext&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;WidgetRef&lt;/span&gt; &lt;span class="n"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Card&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
       &lt;span class="c1"&gt;// The UI code to display each product as a Card&lt;/span&gt;
       &lt;span class="c1"&gt;// UI code removed for brevity and clarity.&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ProductListView&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="n"&gt;ConsumerWidget&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;ProductListView&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="nd"&gt;@override&lt;/span&gt;
  &lt;span class="n"&gt;Widget&lt;/span&gt; &lt;span class="n"&gt;build&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BuildContext&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;WidgetRef&lt;/span&gt; &lt;span class="n"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;cart&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ref&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;watch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cartProvider&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Scaffold&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="nl"&gt;body:&lt;/span&gt; &lt;span class="n"&gt;Container&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nl"&gt;height:&lt;/span&gt; &lt;span class="mi"&gt;600&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
         &lt;span class="c1"&gt;// UI/Widget Code goes here&lt;/span&gt;
        &lt;span class="c1"&gt;// It contains a listview builder&lt;/span&gt;
       &lt;span class="c1"&gt;// iterating through the list...&lt;/span&gt;
      &lt;span class="c1"&gt;// of provided products;&lt;/span&gt;
      &lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;It's that simple.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use ref.read() to call the modification methods
&lt;/h2&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;


&lt;span class="c1"&gt;// surrounding code removed for brevity&lt;/span&gt;
    &lt;span class="n"&gt;IconButton&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                  &lt;span class="nl"&gt;icon:&lt;/span&gt; &lt;span class="n"&gt;Icon&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Icons&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;remove&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
                  &lt;span class="nl"&gt;onPressed:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="n"&gt;ref&lt;/span&gt;
                        &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cartProvider&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;notifier&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                        &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;decreaseQuantityAtIndex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
                  &lt;span class="p"&gt;},&lt;/span&gt;
                &lt;span class="p"&gt;),&lt;/span&gt;



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;While we could use ref.watch and it would work, ref.read is the better candidate for calling the state modification methods because it reads the provider once but without listening to state changes. &lt;/p&gt;

&lt;p&gt;This ensures we never run into race conditions.&lt;/p&gt;

&lt;p&gt;You will observe that we are not reading the provider, but the "notifier" method on it. This is because that's the only to access the modification method on a provider.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fycu2pp6hefzo912phz0l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fycu2pp6hefzo912phz0l.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Reading the provider alone won't expose those methods&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjfrpux3uqrfh8yk24ehd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjfrpux3uqrfh8yk24ehd.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  If you forget anything, don't forget this:
&lt;/h3&gt;

&lt;p&gt;• Use ref.watch in Build Methods, and &lt;br&gt;
• use ref.read in Callbacks;&lt;/p&gt;

&lt;p&gt;No need to call SetState or notifyListeners — Riverpod does that automatically for you.&lt;/p&gt;

&lt;h2&gt;
  
  
  If you are confused with the whole thing...
&lt;/h2&gt;

&lt;p&gt;Remember that converting Futures, Streams, and Simple Objects into their respective Providers is a one-step, simple process. That's because they don't have methods acting on them.&lt;/p&gt;

&lt;p&gt;The case is different with Complex Objects which also have methods acting on them. This is why we first wrap it in a StateNotifier before converting it into its respective Provider;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Still confused? Reach out to me on Twitter;&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Todo Challenge
&lt;/h2&gt;

&lt;p&gt;We've achieved a lot at this point in our state Management journey.&lt;/p&gt;

&lt;p&gt;We learnt how to Create, Read, Update, and Delete data that influences our app's state. We learnt how to make our widgets respond to user input and cause changes on another widget without relying on callbacks. &lt;/p&gt;

&lt;p&gt;It's been a job well done.&lt;/p&gt;

&lt;p&gt;However, our simple cart service isn't entirely complete yet. There are a few loose ends that need to be tied up. So, I'm leaving you with five final challenges:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Complete the implementation of the addToCart method.&lt;/li&gt;
&lt;li&gt;Make the Wishlist icon respond to the isWishlisted field.&lt;/li&gt;
&lt;li&gt;Create a method for decreasing the item count in the cart.&lt;/li&gt;
&lt;li&gt;Create a method to delete a product from the Cart completely.&lt;/li&gt;
&lt;li&gt;Provide a warning to the user when they attempt to decrease the item count when it's already at count 1.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Tweet at me with your solutions &lt;a href="https://twitter.com/AsaboroD" rel="noopener noreferrer"&gt;@AsaboroD&lt;/a&gt; &lt;/p&gt;

</description>
      <category>flutter</category>
      <category>dart</category>
      <category>riverpod</category>
      <category>statemanagement</category>
    </item>
    <item>
      <title>StateNotifier, ChangeNotifier — Why, When, and How to use them.</title>
      <dc:creator>danielAsaboro</dc:creator>
      <pubDate>Fri, 10 Nov 2023 06:39:12 +0000</pubDate>
      <link>https://forem.com/danielasaboro/statenotifier-changenotifier-why-when-and-how-to-use-them-2l6j</link>
      <guid>https://forem.com/danielasaboro/statenotifier-changenotifier-why-when-and-how-to-use-them-2l6j</guid>
      <description>&lt;p&gt;StateProvider becomes unnecessarily challenging when you need to perform operations more complex than the basic counter increment and decrement example that we are commonly used to in Flutter.&lt;/p&gt;

&lt;p&gt;In fact, it will fail when it comes to executing asynchronous operations or data transformations which involves applying conditional logic to a List Of Products in a Cart like in a Checkout Page.&lt;/p&gt;

&lt;p&gt;And that's because it's just not suited for that specific purpose.&lt;/p&gt;

&lt;p&gt;In cases where you are somehow able to manoeuvre your way through, your app's business logic will be littered all around the UI. This lack of clear separation of concerns can quickly lead to a tangled and hard-to-maintain codebase – a sure recipe for disaster in any sizable project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Thankfully, there's a better Alternative...
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Class Variant Providers.
&lt;/h3&gt;

&lt;p&gt;All the Providers we discussed in the previous episode (Provider, FutureProvider, StreamProvider, and StateProvider) are called Function variant Providers because they are basically all functions.&lt;/p&gt;

&lt;p&gt;Like functional programming, that comes with an implication:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Disorganization, &lt;/li&gt;
&lt;li&gt;Little to no encapsulation, &lt;/li&gt;
&lt;li&gt;Near-zero reusability,&lt;/li&gt;
&lt;li&gt;No form of modularity etc... &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Making maintainability and Testing very difficult.&lt;/p&gt;

&lt;p&gt;OOP, on the other hand, lets you bundle data and methods that operate on it within a class. This makes documentation, debugging, and collaboration easy peasy.&lt;/p&gt;

&lt;h2&gt;
  
  
  The same Principle applies to Class Variants Providers
&lt;/h2&gt;

&lt;p&gt;Class variants let you encapsulate the state and the logic for handling and providing data in a class. There are two ways of doing that in RiverPod:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;StateNotifier and&lt;/li&gt;
&lt;li&gt;ChangeNotifier&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  But I see ChangeNotifier as an Impostor
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F51hsj86979stgbgrvuiq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F51hsj86979stgbgrvuiq.png" alt="Change Notifier is an impostor"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Its use is heavily discouraged because it allows mutable states. Mutable States have been historically known to be susceptible to subtle bugs, race conditions, and synchronization overhead.&lt;/p&gt;

&lt;p&gt;While ChangeNotifier is heavily relied upon in Provider, it's only added in Riverpod to make the transition from Provider to Riverpod easy. So we will not talk about it beyond that. &lt;/p&gt;

&lt;p&gt;As a result, StateNotifier will be this piece's focus.&lt;/p&gt;

&lt;h2&gt;
  
  
  StateNotifier: What is it?
&lt;/h2&gt;

&lt;p&gt;StateNotifier is a simple solution to control state in an immutable manner". It's native to Flutter. And RiverPod only re-exports (not that you should care).&lt;/p&gt;

&lt;p&gt;Alright, enough of the pedantic details. &lt;br&gt;
Nothing beats seeing it in action.&lt;/p&gt;

&lt;h2&gt;
  
  
  StateNotifier In Action
&lt;/h2&gt;

&lt;p&gt;Say you are tasked with building the Cart Page Features of an E-commerce app. Below are some of the required useful functionalities...&lt;/p&gt;

&lt;p&gt;Ability to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Flat-out delete an Item(s).&lt;/li&gt;
&lt;li&gt;Mark an Item as a Wish and Move to the WishList&lt;/li&gt;
&lt;li&gt;Increase or Decrease the quantity of an Item on the list&lt;/li&gt;
&lt;li&gt;Recalculate the total price after each change.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Can you implement all of this with a StateProvider?
&lt;/h4&gt;

&lt;p&gt;If yes, please link to your code In the comment section :)&lt;/p&gt;

&lt;p&gt;While you are it, let's see how with a StateNotifier in 7 simple steps.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Define what makes a Product
&lt;/h2&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;


&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Product&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;isWishlisted&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="n"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="kd"&gt;required&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="kd"&gt;required&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="kd"&gt;required&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;price&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;quantity&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;isWishlisted&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="nd"&gt;@override&lt;/span&gt;
  &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="n"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;'Product{id: &lt;/span&gt;&lt;span class="si"&gt;$id&lt;/span&gt;&lt;span class="s"&gt;, name: &lt;/span&gt;&lt;span class="si"&gt;$name&lt;/span&gt;&lt;span class="s"&gt;, price: &lt;/span&gt;&lt;span class="si"&gt;$price&lt;/span&gt;&lt;span class="s"&gt;, quantity: &lt;/span&gt;&lt;span class="si"&gt;$quantity&lt;/span&gt;&lt;span class="s"&gt;, isWishlisted: &lt;/span&gt;&lt;span class="si"&gt;$isWishlisted&lt;/span&gt;&lt;span class="s"&gt;}'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  You notice how all fields are marked final...?
&lt;/h3&gt;

&lt;p&gt;This makes the class immutable which is a good thing as it becomes easier to compare the previous and the new state to check whether they are equal, implement an undo-redo mechanism, and debug the application state.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 2: Define what a Cart Entails
&lt;/h2&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;


&lt;span class="c1"&gt;//... preceding code removed for brevity&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Cart&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;_productList&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="n"&gt;Cart&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="kd"&gt;required&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;productList&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;_productList&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;productList&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="kd"&gt;get&lt;/span&gt; &lt;span class="n"&gt;totalPrice&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//TODO&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="kd"&gt;get&lt;/span&gt; &lt;span class="n"&gt;productList&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;_productList&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="n"&gt;Cart&lt;/span&gt; &lt;span class="n"&gt;copyWith&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="n"&gt;productList&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Cart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="nl"&gt;productList:&lt;/span&gt; &lt;span class="n"&gt;productList&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="n"&gt;_productList&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Step 3: Now, create a StateNotifer class that notifies the Provider for every state Change in the enclosed class.
&lt;/h3&gt;

&lt;p&gt;You do this by extending the StateNotifier class and passing the Class you want to track its changes as a parameter to the StateNotifier class type.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;


&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CartNotifier&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="n"&gt;StateNotifier&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Cart&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;CartNotifier&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;Cart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;productList:&lt;/span&gt; &lt;span class="p"&gt;[])));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If that looks confusing, let's break it down:&lt;/p&gt;

&lt;p&gt;If you take a glimpse at the source code, you will find out that a StateNotifier is an abstract class which means it can't be instantiated but it can be extended. &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
 dart

abstract class StateNotifier&amp;lt;T&amp;gt; {
// class definition goes here
}



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You will also notice that it's a Generic class of type T (StateNotifier), which means you can pass whatever class you like to its type parameter.&lt;/p&gt;

&lt;p&gt;When you do that, the resulting StateNotifier class will Notify others of every state changed in the pass Class type.&lt;/p&gt;

&lt;p&gt;Said differently, your type T is the class you want to convert into a StateNotifier Class, and your classNotifier Class is the resulting combination after the operation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Moving on...
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvtku4a4s1zbn5imh84rd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvtku4a4s1zbn5imh84rd.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What you see in the Super function call is just me calling the constructor of the SuperClass that was extended. This is what we've been doing all our lives when we create a Stateless or Stateful Widget.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;HomePageScreen&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="n"&gt;StatelessWidget&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;HomePageScreen&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="n"&gt;Key&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;key:&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nd"&gt;@override&lt;/span&gt;
  &lt;span class="n"&gt;Widget&lt;/span&gt; &lt;span class="n"&gt;build&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BuildContext&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;Placeholder&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Step 4: Add your state modification methods to the StateNotifier class
&lt;/h2&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;


&lt;span class="c1"&gt;//All previous package imports apply but are removed for brevity&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CartNotifier&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="n"&gt;StateNotifier&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Cart&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;CartNotifier&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
      &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;Cart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;productList:&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;[])));&lt;/span&gt;

  &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;addToCart&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;//TODO&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;removeThisElementFromCart&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//TODO&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;increaseQuantityAtIndex&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//TODO&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;decreaseQuantityAtIndex&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//TODO&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;toggleWishlist&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="c1"&gt;//TODO&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;




&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Do you see how each modification function returns nothing?&lt;br&gt;
Their only job is to change state, nothing more.&lt;/p&gt;

&lt;p&gt;I won't implement the addToCard method for two reasons: It will stretch the length of the tutorial and Two, which is the most important — it's a good take-home practice exercise.&lt;/p&gt;

&lt;p&gt;Instead, we will implement the removeThisElementFromCart method. As a result, I will give you a list of Products to manipulate as a starting Point.&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;

&lt;p&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="s"&gt;'package:flutter/material.dart'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;br&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="s"&gt;'package:flutter_riverpod/flutter_riverpod.dart'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;productListPassed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;br&gt;
  &lt;span class="n"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;br&gt;
    &lt;span class="nl"&gt;id:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
    &lt;span class="nl"&gt;name:&lt;/span&gt; &lt;span class="s"&gt;'Product A'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
    &lt;span class="nl"&gt;price:&lt;/span&gt; &lt;span class="mf"&gt;19.99&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
    &lt;span class="nl"&gt;quantity:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
    &lt;span class="nl"&gt;isWishlisted:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
  &lt;span class="p"&gt;),&lt;/span&gt;&lt;br&gt;
  &lt;span class="n"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;br&gt;
    &lt;span class="nl"&gt;id:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
    &lt;span class="nl"&gt;name:&lt;/span&gt; &lt;span class="s"&gt;'Product B'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
    &lt;span class="nl"&gt;price:&lt;/span&gt; &lt;span class="mf"&gt;29.99&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
    &lt;span class="nl"&gt;quantity:&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
    &lt;span class="nl"&gt;isWishlisted:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
  &lt;span class="p"&gt;),&lt;/span&gt;&lt;br&gt;
  &lt;span class="n"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;br&gt;
    &lt;span class="nl"&gt;id:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
    &lt;span class="nl"&gt;name:&lt;/span&gt; &lt;span class="s"&gt;'Product C'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
    &lt;span class="nl"&gt;price:&lt;/span&gt; &lt;span class="mf"&gt;9.99&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
    &lt;span class="nl"&gt;quantity:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
    &lt;span class="nl"&gt;isWishlisted:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
  &lt;span class="p"&gt;),&lt;/span&gt;&lt;br&gt;
  &lt;span class="c1"&gt;// Add more products as needed&lt;/span&gt;&lt;br&gt;
&lt;span class="p"&gt;];&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CartNotifier&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="n"&gt;StateNotifier&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Cart&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br&gt;
  &lt;span class="n"&gt;CartNotifier&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;br&gt;
      &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;Cart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;productList:&lt;/span&gt; &lt;span class="n"&gt;productListPassed&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;addToCart&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br&gt;
  &lt;span class="c1"&gt;//TODO&lt;/span&gt;&lt;br&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;removeThisElementFromCart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;productIndex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br&gt;
    &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;productList&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;productList&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;br&gt;
    &lt;span class="n"&gt;productList&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;removeAt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;productIndex&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;br&gt;
    &lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;copyWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;productList:&lt;/span&gt; &lt;span class="n"&gt;productList&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;br&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Let's break down what just happened in the removeThisElementFromCart Method&lt;br&gt;
&lt;/h3&gt;

&lt;p&gt;we know how our Cart is basically a List of Products and to access each product, all we need to do is identify its index (which is what is passed to the function as a parameter)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5xhmktn9dkvpfqsit1k6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5xhmktn9dkvpfqsit1k6.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  In line 1 of the function body...
&lt;/h3&gt;

&lt;p&gt;we extracted the current list of products in the state object and saved it to the &lt;em&gt;"productList"&lt;/em&gt; variable.&lt;/p&gt;

&lt;p&gt;The variable "state" is Riverpod's way of representing the current state of the Class passed to the StateNotifier Class which in our case is the Cart object.&lt;/p&gt;

&lt;p&gt;As you can see in the following screenshot, it also gives you access to all the fields and methods available on the Cart Object&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4xn7y3haapn5zkxubzl8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4xn7y3haapn5zkxubzl8.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Line 2 is pretty straightforward
&lt;/h3&gt;

&lt;p&gt;We removed the item at the passed index. YOu can read about the removeAt method here on &lt;a href="https://api.flutter.dev/flutter/dart-core/List/removeAt.html" rel="noopener noreferrer"&gt;Flutter Documentation website.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All it does is remove the item at the specified index from the list, reduce the length by one, and move other items down by one position.&lt;/p&gt;

&lt;h3&gt;
  
  
  And Finally...
&lt;/h3&gt;

&lt;p&gt;In line 3, we reassign the state variables.&lt;/p&gt;

&lt;p&gt;Internally, this triggers two actions. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It compares the previous state value with the current one,&lt;/li&gt;
&lt;li&gt;It calls NotifyListeners() only when the values are not equal.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;NotifyListeners is what informs all subscribed listeners to a state object of a change in value. But before it can do that, we need to link our StateNotifier class to our Widgets(UI Elements).&lt;/p&gt;

&lt;p&gt;And the only way to do that is by using a Provider.&lt;/p&gt;

&lt;p&gt;Since our StateNotifier is not just your typical object, we can't use a futureprovider, streamprovider, or Stateprovider. So we will need a special Provider to help us do that. &lt;/p&gt;

&lt;p&gt;It's called the StateNotifierProvider and it will be the focus of our next lesson.&lt;/p&gt;

</description>
      <category>riverpod</category>
      <category>dart</category>
      <category>mobile</category>
      <category>flutter</category>
    </item>
    <item>
      <title>So many providers in RiverPod 😱😱 Which one should I use?</title>
      <dc:creator>danielAsaboro</dc:creator>
      <pubDate>Sat, 21 Oct 2023 06:04:52 +0000</pubDate>
      <link>https://forem.com/danielasaboro/so-many-providers-in-riverpod-which-one-should-i-use-160m</link>
      <guid>https://forem.com/danielasaboro/so-many-providers-in-riverpod-which-one-should-i-use-160m</guid>
      <description>&lt;p&gt;I hardly pay attention in my English class back in High School.&lt;/p&gt;

&lt;p&gt;I thought I wouldn't need it. &lt;/p&gt;

&lt;p&gt;After all, I would be majoring in Engineering. "Just focus on your Science-based subject", which I did, and thankfully, I got admitted to the most competitive school in my home country.&lt;/p&gt;

&lt;p&gt;However, my time at the university taught me that I was wrong about my view of the English Language, so I struggled when writing Lab Reports and giving a Presentation on a Project. And it's been one of the sources of the biggest setback I've had in my career.&lt;/p&gt;

&lt;p&gt;I've forgotten a lot of things from my time in High School, but one lesson stays stuck to date. And it is...&lt;/p&gt;

&lt;h2&gt;
  
  
  No two English words mean the exact same thing
&lt;/h2&gt;

&lt;p&gt;It's something my English Teacher would say repeatedly when we do some fill-in-the-gap textbook exercises. In his words, "You can use some words interchangeably, but not in all situations". &lt;/p&gt;

&lt;p&gt;I like to think of providers in Riverpod the same way.&lt;/p&gt;

&lt;h3&gt;
  
  
  No two providers have the exact same function
&lt;/h3&gt;

&lt;p&gt;You can use them interchangeably, yes. But only in certain situations. So I will never understand people who talk about "8 types of providers doing the same work". All it screams to me is they don't understand the tool in the first place and don't want to spend time learning it.&lt;/p&gt;

&lt;p&gt;What's worse though, is that most of these complaints originate from people who will never change to Riverpod even if you point a gun directly at their skull, partly for the dreaded fear of being a beginner again.&lt;/p&gt;

&lt;p&gt;But you are different.&lt;/p&gt;

&lt;p&gt;You know better. You know that the creator of Freezed, Flutter_hooks, and Provider definitely has more productive uses for their time than developing providers with overlapping functionality. And you want to learn and use it to design Functional mobile apps. So let's start the article proper!!!.&lt;/p&gt;

&lt;h2&gt;
  
  
  Each Provider explained
&lt;/h2&gt;

&lt;p&gt;For easy understanding, I like to group all Providers into two classes: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Function Variants.&lt;/li&gt;
&lt;li&gt;Class Variants.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In Function Variants, you define providers as functions. &lt;/p&gt;

&lt;p&gt;These functions return the data you want to provide. You can use various types of providers, like StateProvider, FutureProvider, and StreamProvider. They are easy to set up and are great for simple use cases.&lt;/p&gt;

&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Function Variant:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Provider&lt;/li&gt;
&lt;li&gt;StateProvider&lt;/li&gt;
&lt;li&gt;FutureProvider&lt;/li&gt;
&lt;li&gt;StreamProvider&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;

&lt;p&gt;So let's dive into each.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Provider
&lt;/h3&gt;

&lt;p&gt;This is the simplest of them all.&lt;/p&gt;

&lt;p&gt;It's what you would normally use to provide simple immutable objects( data that doesn't change) to multiple parts of your app.&lt;/p&gt;

&lt;p&gt;Examples of this data are a Websocket connection, Database connection, or an Authenticated User Instance — basically, anything you'd want to represent as a singleton.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="s"&gt;'package:flutter/material.dart'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="s"&gt;'package:hooks_riverpod/hooks_riverpod.dart'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;nameProvider&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Provider&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;((&lt;/span&gt;&lt;span class="n"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"Daniel Asaboro"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;RandomPage&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="n"&gt;StatelessWidget&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;RandomPage&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="nd"&gt;@override&lt;/span&gt;
  &lt;span class="n"&gt;Widget&lt;/span&gt; &lt;span class="n"&gt;build&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BuildContext&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Scaffold&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="nl"&gt;body:&lt;/span&gt; &lt;span class="n"&gt;Center&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nl"&gt;child:&lt;/span&gt; &lt;span class="n"&gt;Consumer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
          &lt;span class="nl"&gt;builder:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;child&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ref&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;watch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nameProvider&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;//Daniel Asaboro&lt;/span&gt;
          &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. StateProvider
&lt;/h3&gt;

&lt;p&gt;StateProvider is the next rung after the basic Provider. &lt;/p&gt;

&lt;p&gt;It's a Provider that lets you store simple mutable objects so you can modify its state. However, it exists primarily for working with simple variables such as booleans, integers, and Strings.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="s"&gt;'package:flutter/material.dart'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="s"&gt;'package:hooks_riverpod/hooks_riverpod.dart'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;nameProvider&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;StateProvider&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;((&lt;/span&gt;&lt;span class="n"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;RandomPage&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="n"&gt;ConsumerWidget&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;RandomPage&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="nd"&gt;@override&lt;/span&gt;
  &lt;span class="n"&gt;Widget&lt;/span&gt; &lt;span class="n"&gt;build&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BuildContext&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;WidgetRef&lt;/span&gt; &lt;span class="n"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ref&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;watch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nameProvider&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Scaffold&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="nl"&gt;body:&lt;/span&gt; &lt;span class="n"&gt;Center&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nl"&gt;child:&lt;/span&gt; &lt;span class="n"&gt;Column&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
          &lt;span class="nl"&gt;children:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="n"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="n"&gt;ElevatedButton&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
              &lt;span class="nl"&gt;onPressed:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="c1"&gt;// This will change the output in Text widget to "Daniel Asaboro"&lt;/span&gt;
                &lt;span class="n"&gt;ref&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nameProvider&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;notifier&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Daniel Asaboro"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
              &lt;span class="p"&gt;},&lt;/span&gt;
              &lt;span class="nl"&gt;child:&lt;/span&gt; &lt;span class="n"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Change Name"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="p"&gt;),&lt;/span&gt;
          &lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Its use is heavily discouraged because it allows easy modification from anywhere and from any widget — don't too many cooks spoil the broth?&lt;/p&gt;

&lt;p&gt;This is why it's only useful for maintaining local state i.e. state that doesn't need to be shared across the entire application e.g. Passing the Index of a selected item in a List to another function or Provider which we will talk about later in the series.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. FutureProvider
&lt;/h3&gt;

&lt;p&gt;FutureProvider is your guy when you need to supply values that are resolved asynchronously, such as API network calls or database queries. FutureProvider makes working with futures and async operations a work in the park.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="s"&gt;'package:flutter/material.dart'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="s"&gt;'package:hooks_riverpod/hooks_riverpod.dart'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="s"&gt;'package:http/http.dart as http;
import '&lt;/span&gt;&lt;span class="nl"&gt;dart:&lt;/span&gt;&lt;span class="n"&gt;convert&lt;/span&gt;&lt;span class="s"&gt;';

final nameProvider = FutureProvider&amp;lt;Map&amp;lt;String, dynamic&amp;gt;&amp;gt;((ref) async {
  final response =
      await http.get(Uri.parse('&lt;/span&gt;&lt;span class="nl"&gt;https:&lt;/span&gt;&lt;span class="c1"&gt;//jsonplaceholder.typicode.com/users/5'));&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;statusCode&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="n"&gt;Exception&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Failed to load data'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;RandomPage&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="n"&gt;ConsumerWidget&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;RandomPage&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="nd"&gt;@override&lt;/span&gt;
  &lt;span class="n"&gt;Widget&lt;/span&gt; &lt;span class="n"&gt;build&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BuildContext&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;WidgetRef&lt;/span&gt; &lt;span class="n"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;ref&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;watch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nameProvider&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;when&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
          &lt;span class="nl"&gt;data:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Scaffold&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
              &lt;span class="nl"&gt;body:&lt;/span&gt; &lt;span class="n"&gt;Center&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="nl"&gt;child:&lt;/span&gt; &lt;span class="n"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;]),&lt;/span&gt; &lt;span class="c1"&gt;//"Chelsey Dietrich"&lt;/span&gt;
              &lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="p"&gt;);&lt;/span&gt;
          &lt;span class="p"&gt;},&lt;/span&gt;
          &lt;span class="nl"&gt;error:&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stackTrace&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="si"&gt;${error.toString()}&lt;/span&gt;&lt;span class="s"&gt;, &lt;/span&gt;&lt;span class="si"&gt;$stackTrace&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
          &lt;span class="p"&gt;}),&lt;/span&gt;
          &lt;span class="nl"&gt;loading:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;CircularProgressIndicator&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
        &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. StreamProvider
&lt;/h3&gt;

&lt;p&gt;StreamProvider is used for providing values that come from a continuous stream of data like real-time stock market updates, football match live scores, or WebSocket events. &lt;/p&gt;

&lt;p&gt;A common use-case for StreamProvider is providing stream data from a real-time  database like Firestore. Some use it in chat applications, and some in Video-calls.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="s"&gt;'dart:async'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="s"&gt;'package:flutter/material.dart'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="s"&gt;'package:hooks_riverpod/hooks_riverpod.dart'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="s"&gt;'package:socket_io_client/socket_io_client.dart'&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;IO&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;SocketService&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="n"&gt;serverUrl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"http://your.socket.io.server.url"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;IO&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;Socket&lt;/span&gt; &lt;span class="n"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// Stream controller for broadcasting live weather data&lt;/span&gt;
  &lt;span class="n"&gt;StreamController&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;_weatherDataController&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;StreamController&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;();&lt;/span&gt;

  &lt;span class="n"&gt;SocketService&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Initialize the Socket.IO connection&lt;/span&gt;
    &lt;span class="n"&gt;socket&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;IO&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;io&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;serverUrl&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;dynamic&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;{&lt;/span&gt;
      &lt;span class="s"&gt;'transports'&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'websocket'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
      &lt;span class="s"&gt;'autoConnect'&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="c1"&gt;// Define an event to receive live weather data from the server&lt;/span&gt;
    &lt;span class="n"&gt;socket&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'weatherData'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="c1"&gt;// Add the data to the stream&lt;/span&gt;
      &lt;span class="n"&gt;_weatherDataController&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="n"&gt;Stream&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;getLiveWeatherData&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;_weatherDataController&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;stream&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;dispose&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;_weatherDataController&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;close&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="n"&gt;socket&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;disconnect&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;socketProvider&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Provider&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;SocketService&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;((&lt;/span&gt;&lt;span class="n"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;SocketService&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;socketStreamProvider&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;StreamProvider&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kd"&gt;async&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;streamData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ref&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;watch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;socketProvider&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getLiveWeatherData&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;eachLiveData&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;streamData&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="n"&gt;eachLiveData&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;RandomPage&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="n"&gt;ConsumerWidget&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;RandomPage&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="nd"&gt;@override&lt;/span&gt;
  &lt;span class="n"&gt;Widget&lt;/span&gt; &lt;span class="n"&gt;build&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BuildContext&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;WidgetRef&lt;/span&gt; &lt;span class="n"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;ref&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;watch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;socketStreamProvider&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;when&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
          &lt;span class="nl"&gt;data:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Scaffold&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
              &lt;span class="nl"&gt;body:&lt;/span&gt; &lt;span class="n"&gt;Center&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="nl"&gt;child:&lt;/span&gt; &lt;span class="n"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="c1"&gt;//some string;&lt;/span&gt;
              &lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="p"&gt;);&lt;/span&gt;
          &lt;span class="p"&gt;},&lt;/span&gt;
          &lt;span class="nl"&gt;error:&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stackTrace&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="si"&gt;${error.toString()}&lt;/span&gt;&lt;span class="s"&gt;, &lt;/span&gt;&lt;span class="si"&gt;$stackTrace&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
          &lt;span class="p"&gt;}),&lt;/span&gt;
          &lt;span class="nl"&gt;loading:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;CircularProgressIndicator&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
        &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, it's quite similar to FutureProvider as they both deal with asynchronous data. And Riverpod gives us an easy way to handle all its possible states from Loading, to when it gets Data or Errors out;&lt;/p&gt;

&lt;h2&gt;
  
  
  We've come a long way
&lt;/h2&gt;

&lt;p&gt;We've spoke about the four fundamental providers in Flutter: Provider, StateProvider, FutureProvider, and StreamProvider. While they've all proven to be invaluable tools in managing data, state, and asynchronous operations in your app easily, they do have certain limitations.&lt;/p&gt;

&lt;p&gt;Most are read-only and only focus on data distribution.&lt;/p&gt;

&lt;p&gt;What if you need more than that? &lt;/p&gt;

&lt;p&gt;Say you need to retrieve a User biodata from the server, edit and update it, and then send it back to the server, that's a lot of operations — none of the Providers we've talked about can do that. &lt;/p&gt;

&lt;p&gt;This is the gap Class variant Providers fill. &lt;/p&gt;

&lt;p&gt;As its name implies, it lets you group related methods for working on a particular data together. It will be the focus of the next episode in this series. We will take a deep dive, and talk about why they are useful, when to use them, and how.&lt;/p&gt;

&lt;p&gt;Till then...bye.&lt;/p&gt;

</description>
      <category>dart</category>
      <category>fluttter</category>
      <category>riverpod</category>
      <category>statemanagement</category>
    </item>
    <item>
      <title>Explaining RiverPod like I'm 5 — From someone who finally got it!</title>
      <dc:creator>danielAsaboro</dc:creator>
      <pubDate>Tue, 17 Oct 2023 04:26:34 +0000</pubDate>
      <link>https://forem.com/danielasaboro/explaining-riverpod-like-im-5-from-someone-who-finally-got-it-4dge</link>
      <guid>https://forem.com/danielasaboro/explaining-riverpod-like-im-5-from-someone-who-finally-got-it-4dge</guid>
      <description>&lt;p&gt;The First Communication Satellite (Telstar 1) was launched &lt;a href="https://en.wikipedia.org/wiki/Telstar_1" rel="noopener noreferrer"&gt;in July 1962.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thirteen days later, the first live broadcast of a television show between the United States and Europe took place. That evening, Telstar 1 also relayed the first satellite telephone call, between U.S. vice-president Lyndon Johnson and the chairman of AT&amp;amp;T, Frederick Kappel.&lt;/p&gt;

&lt;p&gt;From then on, information that would normally take months to transmit took minutes. Insane jump in productivity, but it didn't happen overnight.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Satellite Communication works
&lt;/h2&gt;

&lt;p&gt;It works by relaying signals through orbiting satellites in low Earth orbit. It begins with a ground-based transmitter sending data or voice signals to a satellite dish pointed at the specific satellite in orbit. &lt;/p&gt;

&lt;p&gt;The satellite then captures these signals, manipulates them, and then retransmits them back to a ground station in another location. This process allows for long-distance communication and is vital for services like television broadcasts, internet access, and even global navigation systems like GPS.&lt;/p&gt;

&lt;p&gt;What has that to do with State Management? Or Riverpod? You ask&lt;/p&gt;

&lt;h2&gt;
  
  
  State Management Tools operate much like Satellites
&lt;/h2&gt;

&lt;p&gt;They wrap around your app like orbiting satellites wrap around the Earth, and ensure that data flow is smooth, predictable, and efficient.&lt;/p&gt;

&lt;p&gt;Riverpod is not in any way different.&lt;/p&gt;

&lt;p&gt;This is why the number one prerequisite for using it in your app is wrapping the whole thing with the ProviderScope widget. Else, nothing would work.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh5lwzb31jk5hwnc0cwjl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh5lwzb31jk5hwnc0cwjl.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;JSYK, I failed at my short stint as a Graphic designer back in 2019. Saying that before you attack my skills 🙈☹️&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Interestingly, that's also how the MaterialApp Widget works!
&lt;/h2&gt;

&lt;p&gt;Once you wrap your app with the MaterialApp Widget, you will be able to access core features like Theming, Navigation, and most importantly, the BuildContext (a crucial object that provides a reference to a widget location within the widget tree, allowing them access information and resources from their surrounding environment and the overall app).&lt;/p&gt;

&lt;p&gt;Else, nothing for you 💀&lt;/p&gt;

&lt;p&gt;I remember the first time  I picked up Flutter and forgot to wrap my text in a scaffold, see how bad it was...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foe9o4s0htjctxn2mudxd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foe9o4s0htjctxn2mudxd.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now imagine how bad it can get when you don't wrap MaterialApp...💀&lt;/p&gt;

&lt;p&gt;In the same way that the MaterialApp has BuildContext, Riverpod ProviderScope also gives us a reference called WidgetRef. &lt;/p&gt;

&lt;p&gt;The way I like to put it is MaterialApp provides the UI-related code while Riverpod provides the App's Logic-related code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5qm87zwm2paadlp9bj7r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5qm87zwm2paadlp9bj7r.png" alt="1 to 1 map between MaterialApp and RiverPod"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  But there's a small tiny-bitty problem ☹️
&lt;/h2&gt;

&lt;p&gt;While you can access BuildContext by simply wrapping your app in the MaterialApp Widget, you can't access the WidgetRef that easily. All you will get is red squiggly lines.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Far0nhrnjgmf3tp6mvmtg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Far0nhrnjgmf3tp6mvmtg.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;☹️&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjht7973k4f7tj850rhhj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjht7973k4f7tj850rhhj.png" alt="WidgetRef isn't a valid override of StatelessWidget Build"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;(Error: WidgetRef isn't a valid override of StatelessWidget Build)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;While we could access the buildContext, the same can't be said for the WidgetRef even after importing Riverpod. Thankfully, the solution is easy. So let's dive into it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three ways to Access RiverPod WidgetRef
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Using the Consumer Widget
&lt;/h3&gt;

&lt;p&gt;Most people think this is the simplest way to use Riverpod WidgetRef in your app, but I don't. However, I think it's the most straightforward way apart from the boilerplate code, as it's what you are already used to.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffr81dkpwhtsh0w5g3vu9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffr81dkpwhtsh0w5g3vu9.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Simply wrap a Consumer Widget around the widget that needs to react to state changes or some external dependencies.&lt;/p&gt;

&lt;p&gt;And the code isn't that complicated.&lt;/p&gt;

&lt;h3&gt;
  
  
  Let's break it down:
&lt;/h3&gt;

&lt;p&gt;The Consumer widget has a required field called the builder which is responsible for rebuilding the widget whenever the provider value changes. &lt;/p&gt;

&lt;p&gt;It's very similar to the FutureBuilder, StreamBuilder, or the AnimationBuilder if you are familiar with it and it's a callback function that accepts 3 parameters:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;context (type: BuildContext)&lt;/li&gt;
&lt;li&gt;ref (type: WidgetRef)&lt;/li&gt;
&lt;li&gt;child (type: Widget?) which means optional&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The context is only passing the context from Material App to the builder much like you would do in a dialogue or Alert widget. &lt;/p&gt;

&lt;p&gt;The only new parameter is the WidgetRef which gives the widget — you already guessed it — a reference for subsequent operations.&lt;/p&gt;

&lt;p&gt;We will talk about the child parameter when we get to optimization. I work for startups and trust me, there are better things to do than spending 5 hours making an app 5 milliseconds faster. No wonder it's optional!&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Extending the ConsumerWidget
&lt;/h3&gt;

&lt;p&gt;Textbook definition says "The ConsumerWidget class is a subclass of StatelessWidget that provides built-in Riverpod integration". &lt;/p&gt;

&lt;p&gt;Said simply, the ConsumerWidget inherits behaviour from a Stateless Widget, so it gets the BuildContext automatically, after which it adds the WidgetRef — thereby getting built-in Riverpod integration.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxqot9rser1qs7fwffaqg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxqot9rser1qs7fwffaqg.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The added advantage is accessing your WidgetRef directly from the build method without needing to wrap the widget in a Consumer as shown earlier.&lt;/p&gt;

&lt;p&gt;Note: This code has the same outcome as the example given in method one (wrapping with Consumer).&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Extending the ConsumerStateful Widget
&lt;/h3&gt;

&lt;p&gt;This is the Stateful version of the ConsumerWidget. &lt;/p&gt;

&lt;p&gt;If you find yourself in a situation where you need to perform one-time actions such as fetching setup data or getting the user's location before rendering your page as you would normally do in an initState method, then this is the right approach for you.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8d6hubex2l5pphgcomnu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8d6hubex2l5pphgcomnu.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As always, all three code have the same Output&lt;/p&gt;

&lt;h2&gt;
  
  
  Which one should I use?
&lt;/h2&gt;

&lt;p&gt;Each has its use cases ranging from Readability, Performance, Verbosity etc And like everything in software development, a lot of Experts have their opinions about each. Not an expert, I just build. So I will leave finding out to you.&lt;/p&gt;

&lt;p&gt;The general rule though, is to stick with ConsumerWidget until it's not enough. And that brings us to the end of this lesson. In the next, we will dive deep into the different types of Providers available in Riverpod, how and when to use them.&lt;/p&gt;

&lt;p&gt;Bye.&lt;/p&gt;

</description>
      <category>dart</category>
      <category>flutter</category>
      <category>statemanagement</category>
      <category>riverpod</category>
    </item>
    <item>
      <title>Riverpod easily explained for those who don't get it</title>
      <dc:creator>danielAsaboro</dc:creator>
      <pubDate>Mon, 16 Oct 2023 06:08:36 +0000</pubDate>
      <link>https://forem.com/danielasaboro/riverpod-easily-explained-for-those-who-dont-get-it-4j97</link>
      <guid>https://forem.com/danielasaboro/riverpod-easily-explained-for-those-who-dont-get-it-4j97</guid>
      <description>&lt;p&gt;It takes only a few weeks of intense Fluttering before you quickly realize using callbacks to manage state and data flow across your app is a big pain in the ass.&lt;/p&gt;

&lt;p&gt;Before you know it, your callbacks are 4 to 5 levels deep, changes reflect at a snail's pace, and you start struggling to recognize your codebase should you take any break. Oh, and heaven forbid you forget to call 'SetState' – that's when the real chaos begins.&lt;/p&gt;

&lt;p&gt;I know — because I've been there. It's something you wouldn't wish upon your worst enemy. So I knew it was time to take that big leap in my Flutter learning journey once I saw the signs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Picking a  StateManagement tool
&lt;/h2&gt;

&lt;p&gt;Thankfully, the choice was easy.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F96hhw1fc0id961rox0z7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F96hhw1fc0id961rox0z7.png" alt="Started learning State Management"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Unlike most people, I didn't get stuck deciding what to go with when considering the plethora of choices out there. I simply picked one and stuck with it since then.&lt;/p&gt;

&lt;p&gt;But this couldn't be possible without people like &lt;a href="https://twitter.com/thatsaxydev" rel="noopener noreferrer"&gt;Kiishi&lt;/a&gt;, &lt;a href="https://twitter.com/iamjideguru" rel="noopener noreferrer"&gt;Jide Guru&lt;/a&gt;, and &lt;a href="https://twitter.com/precious_tagy" rel="noopener noreferrer"&gt;Precious&lt;/a&gt;. They couldn't stop raving about Riverpod, and I'm immensely grateful that they didn't.&lt;/p&gt;

&lt;h2&gt;
  
  
  It wasn't an easy journey either
&lt;/h2&gt;

&lt;p&gt;I started learning Flutter precisely on July 12. &lt;/p&gt;

&lt;p&gt;I can never forget that day as it was a turning point in my life. &lt;/p&gt;

&lt;p&gt;A friend who was meant to handle the mobile part of a project we both ideated on while I dealt with the backend suddenly ghosted after we had a few clashes.&lt;/p&gt;

&lt;p&gt;We had applied for a Startup Grant I was very interested in and I couldn't pull out. I either make it work or die trying. And so my Flutter journey began.&lt;/p&gt;

&lt;h2&gt;
  
  
  I had a 3-month hard stop!
&lt;/h2&gt;

&lt;p&gt;For the grant, you're given a choice: either have your MVP up and running within three months, or you won't receive any support. Given my tight schedule and limited time, I couldn't afford to waste a single moment; my sole focus was simple: Building — which I did.&lt;/p&gt;

&lt;p&gt;Fast Forward to today, we already have a working MVP and we have two weeks left to squash bugs. And Riverpod has been quite helpful along the way. It was a breath of fresh air.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sadly, many people find Riverpod so hard and complicated
&lt;/h2&gt;

&lt;p&gt;They say it has so many options to choose from. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnk6g38z3ip09rf8cgkp6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnk6g38z3ip09rf8cgkp6.png" alt="RiverPod"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Even worse — "&lt;em&gt;these options basically do the same thing&lt;/em&gt;", one said. The jargon can be overwhelming, from hooks to Freeze, generators, annotations, and whatever new buzzword pops up tomorrow.&lt;/p&gt;

&lt;p&gt;And they are right.&lt;/p&gt;

&lt;p&gt;But what they forget is that you don't need to use everything a package gives you to make a standard Mobile app. As someone rightly told me a time ago "you can get by using a relatively small subset of the features to cover the cases you’ll need".&lt;/p&gt;

&lt;p&gt;That's precisely what I did.&lt;/p&gt;

&lt;p&gt;So in the upcoming series of articles, I'm going to share my approach with you.&lt;/p&gt;

&lt;p&gt;Don't worry; if I, someone who barely started learning how to write web programs just on April 14th, can grasp these concepts, I'm confident you can too.&lt;/p&gt;

&lt;p&gt;I'll provide code examples, and snippets, and be completely transparent about the mistakes I made along the way. There will be no holding back, and we'll tackle Riverpod together.&lt;/p&gt;

&lt;p&gt;No holdbacks. Promised! &lt;/p&gt;

</description>
      <category>flutter</category>
      <category>riverpod</category>
      <category>dart</category>
      <category>statemanagement</category>
    </item>
    <item>
      <title>Flutter</title>
      <dc:creator>danielAsaboro</dc:creator>
      <pubDate>Sun, 13 Aug 2023 21:52:03 +0000</pubDate>
      <link>https://forem.com/danielasaboro/flutter-4ecj</link>
      <guid>https://forem.com/danielasaboro/flutter-4ecj</guid>
      <description>&lt;p&gt;Flutter, Flutter, Flutter.&lt;/p&gt;

&lt;p&gt;That's the post&lt;/p&gt;

</description>
    </item>
    <item>
      <title>From Novice to Ninja: How I moved from getting scared of Errors to throwing and handling them gracefully</title>
      <dc:creator>danielAsaboro</dc:creator>
      <pubDate>Sun, 30 Jul 2023 13:47:02 +0000</pubDate>
      <link>https://forem.com/danielasaboro/from-novice-to-ninja-how-i-moved-from-getting-scared-of-errors-to-throwing-and-handling-them-gracefully-598a</link>
      <guid>https://forem.com/danielasaboro/from-novice-to-ninja-how-i-moved-from-getting-scared-of-errors-to-throwing-and-handling-them-gracefully-598a</guid>
      <description>&lt;p&gt;Early on in my journey as a developer, I dreaded encountering bugs. &lt;/p&gt;

&lt;p&gt;I thought I was alone. It's only now that I'm beginning to realize it's a common phase everyone goes through. Bug seem like obstacles that stood in the way of a perfectly functioning program. &lt;/p&gt;

&lt;p&gt;Like intruders lurking in the darkest corners, they appear unexpectedly and wreak havoc on your well designed programming flow.&lt;/p&gt;

&lt;p&gt;At first, I resented their existence. &lt;/p&gt;

&lt;p&gt;The only thing I calculate after solving a bug is calculating how much of the time and effort I used in tracking them could have been converted into something productive like opening more PRs and adding more features to the product.&lt;/p&gt;

&lt;p&gt;However, as I gained experience, my perspective began to shift.&lt;/p&gt;

&lt;h2&gt;
  
  
  But my perspective began to change one fateful day
&lt;/h2&gt;

&lt;p&gt;A seemingly simple project I was working on began to throw inexplicable errors. No matter how much I tried to ignore them, they persisted, mocking my skills. Frustration boiled inside me, threatening to consume my enthusiasm for programming but I was broke and can't quit for how far i've come.&lt;/p&gt;

&lt;p&gt;With no other choice, I decided to confront the bugs head-on.&lt;/p&gt;

&lt;p&gt;Instead of dwelling on the problem's complexity, I focused on the process of debugging itself. It was then that I realized the true beauty of debugging – it forces us to scrutinize our code, line by line, examining every tiny detail. &lt;/p&gt;

&lt;p&gt;In the process, I learned how to look at my code from different angles, identify potential pitfalls, and gained a profound understanding of the system's inner workings.&lt;/p&gt;

&lt;p&gt;** One particular experience that stands out was an elusive bug that surfaced only during specific conditions. It haunted me for days, lurking in the shadows of my project. I felt an almost personal vendetta against this bug, and I couldn't rest until I uncovered its source. The countless hours invested in debugging eventually led me to a Eureka moment. Not only did I fix the problem, but I discovered an aspect of the system that I had previously overlooked. The satisfaction I derived from that breakthrough was unparalleled – it was akin to solving a complex puzzle or uncovering a hidden treasure.&lt;/p&gt;

&lt;p&gt;***I recall a particularly perplexing bug that haunted me for days. It involved a seemingly innocent line of code that caused erratic behavior in a critical module. The more I dug into the issue, the deeper the rabbit hole seemed to go. Frustration mounted, and doubts crept in. But it was during this trial that I discovered the true beauty of bugs—they forced me to question my assumptions and delve into the intricacies of the system.&lt;/p&gt;

&lt;h2&gt;
  
  
  Before I hate errors, now I create and throw them.
&lt;/h2&gt;

&lt;p&gt;Bugs give invaluable insights into the system, allowing us to understand its intricacies and grow as developers.&lt;/p&gt;

&lt;p&gt;Embracing them has not only expanded my technical knowledge but also honed my problem-solving skills. Each bug comes with a unique set of challenges, pushing me to think creatively and consider alternative approaches. &lt;/p&gt;

&lt;p&gt;It's like engaging in a sparring match with the system, where I learn from its maneuvers, and becoming a better developer with every encounter.&lt;/p&gt;

&lt;p&gt;Moreover, resolving bugs has made me more empathetic towards fellow developers. We all share this rollercoaster of emotions – from the initial frustration to the exhilaration of triumph when a bug is squashed. It has created a sense of camaraderie within the development community, where we openly share our bug war stories and learn from one another's triumphs and defeats.&lt;/p&gt;

&lt;p&gt;In a world that often emphasizes perfection and the pursuit of flawlessness, I urge fellow developers to embrace the bugs.&lt;/p&gt;

&lt;p&gt;The journey of resolving a bug is akin to solving a challenging puzzle. Each piece of the puzzle brings us closer to unraveling the mystery, and with each solved bug, a profound sense of accomplishment washes over us. The euphoria that accompanies the successful eradication of a bug is unmatched—it fuels our passion and rejuvenates our spirit as developers. The satisfaction is not merely derived from making the system work flawlessly but also from the knowledge that we have honed our skills and grown as problem solvers.&lt;/p&gt;

&lt;p&gt;Bugs, in their essence, are our greatest teachers. They expose the flaws in our logic, challenge our assumptions, and force us to think critically. &lt;/p&gt;

&lt;p&gt;As we navigate the treacherous terrain of debugging, we acquire invaluable lessons that extend far beyond the realm of coding. Perseverance, resilience, attention to detail, and the ability to embrace failure as a stepping stone to success—all these qualities are nurtured through our encounters with bugs.&lt;/p&gt;

&lt;p&gt;To comprehend the inner workings of a software system, one must embrace the bugs within it. Like detectives on a mission, we analyze stack traces, scrutinize log files, and reproduce the elusive errors in controlled environments.&lt;/p&gt;

&lt;p&gt;As we chase after these tiny creatures, we uncover the complex interactions between different components, gaining a deeper understanding of the system's intricacies. &lt;/p&gt;

&lt;p&gt;Instead of seeing them as merely annoyances or roadblocks, we should see them invaluable opportunities for growth and learning, catalysts for self-education, propelling us to become more proficient and knowledgeable developers.&lt;/p&gt;

&lt;p&gt;Ever wonder how your favourite youtubers become so good? they spent so much time than you can fathom dealing with bugs. That's what you should start doing. So also am I.&lt;/p&gt;

&lt;h2&gt;
  
  
  I'm beginning to see Bugs as Friends instead Foes
&lt;/h2&gt;

&lt;p&gt;As a software developer, I have learned to embrace bugs as companions on my journey, rather than adversaries to be feared&lt;br&gt;
They have become an integral part of my growth and understanding of complex systems. &lt;/p&gt;

&lt;p&gt;So, the next time you encounter a bug, instead of succumbing to frustration, try viewing it as an invitation to explore, to learn, and to experience the unparalleled satisfaction that comes from unraveling the intricacies of the system. Embrace the bugs and let them guide you toward becoming a more accomplished and fulfilled developer.&lt;/p&gt;

&lt;p&gt;Bugs can be frustrating and feel like wasted time, but we shouldn't overlook the profound learning opportunities they present.&lt;/p&gt;

&lt;p&gt;I'm not saying you should dive into them with enthusiasm, instead, i'm asking you to embrace them because they are the key to unlocking a deeper understanding of the system.&lt;/p&gt;

&lt;p&gt;They are not signs of failure, but rather opportunities for growth.Bugs remind us that the pursuit of perfection is a never-ending journey, and the joy lies not in achieving it, but in the pursuit itself.&lt;/p&gt;

&lt;p&gt;Bugs are how we gain understanding of the system. Embrace them!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>I took a BIG Leap, but Backwards. Here's why and how it's panning out</title>
      <dc:creator>danielAsaboro</dc:creator>
      <pubDate>Sun, 23 Jul 2023 06:15:26 +0000</pubDate>
      <link>https://forem.com/danielasaboro/dont-do-hard-things-i-took-a-big-leap-but-backwards-heres-why-3pde</link>
      <guid>https://forem.com/danielasaboro/dont-do-hard-things-i-took-a-big-leap-but-backwards-heres-why-3pde</guid>
      <description>&lt;p&gt;Just before June ended, I got a message from my old-time friend.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5p6gg86y1js72x4tyzs7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5p6gg86y1js72x4tyzs7.png" alt="Question from my friend"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The content was plain and small, but it was big enough to make me revisit the thousands of micro-decisions that compounded down to where I am today, what I'm doing, and for whom.&lt;/p&gt;

&lt;p&gt;While I promised to revert, sadly, since then, I've not. This is my attempt to keep up to my word.&lt;/p&gt;

&lt;h2&gt;
  
  
  But first, a quick clarification
&lt;/h2&gt;

&lt;p&gt;It's easy to connect the dots looking backwards, particularly if you are making progress, but the same can't be said in the reverse. So please note that it was a series of tough decisions down here, but I'm glad I made them.&lt;/p&gt;

&lt;h3&gt;
  
  
  I made my debut a long time ago
&lt;/h3&gt;

&lt;p&gt;I got introduced to Programming my last year in High school — Think when Adobeflash and Actionscript were still a thing. Like most beginners, I wasn't fully immersed as I was doing it alongside other things.&lt;/p&gt;

&lt;p&gt;This continued till my first year in the University.&lt;/p&gt;

&lt;p&gt;Then I got introduced to MicroControllers and even competed at various competitions. There, I had to use C++ and learnt it to solve most of the difficulties I faced.&lt;/p&gt;

&lt;p&gt;Simultaneously, I was also learning Html, CSS, Js, PHP, and MYSQL (the languages of the web then).&lt;/p&gt;

&lt;p&gt;This was in 2017/18. Jquery was the trending library at that time. And suddenly, I stopped coding: C++, Microcontrollers, Web development — basically everything. &lt;/p&gt;

&lt;h3&gt;
  
  
  Then covid came out of nowhere!
&lt;/h3&gt;

&lt;p&gt;By this time, it was like a year's break from everything programming. And funny enough, I'd dipped my hand in the Graphics world. You know the usual suspect: Photoshop, Illustrator, and a little bit of Lightroom.&lt;/p&gt;

&lt;p&gt;But I got bored, and quickly.&lt;/p&gt;

&lt;p&gt;For one, I could replicate most designs I saw since I knew the tools, where to find them, and what they could do — but I couldn't create a satisfactory design from scratch no matter how hard I tried.&lt;/p&gt;

&lt;p&gt;Yes, I studied colour theory. &lt;/p&gt;

&lt;p&gt;The wheel. The Psychology. I knew what analogous colours are, what complementary is, and what it means for a set of colours to be Triadic. But I couldn't compose them into something meaningful. Something beautiful. Or, thumb scrolling.&lt;/p&gt;

&lt;h3&gt;
  
  
  No matter how much I studied and tried, I just couldn't.
&lt;/h3&gt;

&lt;p&gt;Perhaps, I'm not good with colours. In some way, it reflects in my clothing style to date. You'd hardly see me deviate from the Neutrals: white, black, brown and other shades in between.&lt;/p&gt;

&lt;p&gt;Perhaps, I wasn't creative. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;But I couldn't stay Idle, so I jumped into 3D.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;At first, It felt exciting.&lt;/p&gt;

&lt;p&gt;All  I wanted to do then was translate everything around me into a 3D digital representation. But I slowly dropped out, albeit painfully (My PC couldn't handle the workload).&lt;/p&gt;

&lt;h3&gt;
  
  
  Then, for some reason, I dabbled into Marketing.
&lt;/h3&gt;

&lt;p&gt;First, it was copywriting.&lt;/p&gt;

&lt;p&gt;I studied the greats: Gary Halbert, Claude Hopkins, David Ogilvy, and Joe Sugarman. I read books like Tested Advertising Methods, Scientific Advertising, and Great Leads — not once, not twice, but over, and over again.&lt;/p&gt;

&lt;p&gt;I picked interest in B2B saas (that was where the money was).&lt;/p&gt;

&lt;p&gt;As a result, I learnt Content Marketing because I realized that relationships are everything in B2B. You have to "nurture" people with "value" so they are comfortable buying from you.&lt;/p&gt;

&lt;p&gt;I did this actively for two years.&lt;/p&gt;

&lt;p&gt;And in that period,  I learnt about SEO, ABM, Customer Research and all that kind of Marketing Jazz. Overall, I improved my writing skills (I'd wrongly assumed I didn't need to be good at writing since I would be an Engineer).&lt;/p&gt;

&lt;p&gt;Coincidentally, that was when I started realizing a few, fundamental, but painful truths about life. I will go over them briefly:&lt;/p&gt;

&lt;h2&gt;
  
  
  Don't do hard things
&lt;/h2&gt;

&lt;p&gt;Down to the course I'm currently studying at the University, all my choices in the past were predicated on doing hard things.&lt;/p&gt;

&lt;p&gt;I didn't need to like them. I just get satisfaction from completing them. But life is too short to spend time playing unnecessary games, you will only end up with unnecessary prices.&lt;/p&gt;

&lt;p&gt;I learnt this lesson, painfully.&lt;/p&gt;

&lt;p&gt;As you grow old, you will realize that society doesn't reward you for doing hard things. Instead, it rewards you for doing things it values but thinks are hard to get.&lt;/p&gt;

&lt;h3&gt;
  
  
  It's a subtle distinction but with profound implications
&lt;/h3&gt;

&lt;p&gt;It reminds me of Naval's quote about society paying you for things it needs but didn't know how to get. It's what made Henry Ford, Rockefeller, and Elon Musk who they are in society.&lt;/p&gt;

&lt;p&gt;They gave society what she needed and got paid for it. In my experience, solving problems at scale with software is one of them, but Marketing isn't.&lt;/p&gt;

&lt;p&gt;I think Marketing is tougher than software development. The space of possible solutions to a problem was unlimited and nondeterministic unlike software, yet people value it widely less (the salaries show it)&lt;/p&gt;

&lt;h2&gt;
  
  
  Two, I was naturally a computer guy
&lt;/h2&gt;

&lt;p&gt;There are several things I know without trying about computer systems that most people have to actively invest time, energy, and resources before they can.&lt;/p&gt;

&lt;p&gt;It might feel like a brag, but it's the truth.&lt;/p&gt;

&lt;p&gt;I was spoofing wifi since I was 13. Did your files got deleted from your USB disk? I could recover it in a few minutes. I was already using cmd to shut down a pc, get a wifi password, or **&lt;/p&gt;

&lt;p&gt;Did your laptop start showing a blue screen error and wouldn't boot up properly? I could diagnose and fix the issue without resorting to professional help or spending unnecessary money on repairs and on and on.&lt;/p&gt;

&lt;p&gt;When I talked at a young age about PCs then, people listened.&lt;/p&gt;

&lt;p&gt;So you can imagine my shock getting into marketing, and two years down the line finding myself in a back-and-forth argument with people who don't have the slightest idea about marketing yet always want to  give advice on it — it's uncommon in the software world.&lt;/p&gt;

&lt;p&gt;I was getting dissatisfied internally as a result. So, I started looking into jumping ship. The opportunity came in February this year.&lt;/p&gt;

&lt;h3&gt;
  
  
  I volunteered for a small Political Party
&lt;/h3&gt;

&lt;p&gt;It's February. My country was holding a presidential election. So I decided to volunteer for a small Political Party with a vision to restore hope, combat corruption, and bring positive change.&lt;/p&gt;

&lt;p&gt;That short month was intensive for me, it set the foundation for my switching back to computer programming. For one, I got to see firsthand, how useful tech is, and the big impact it can make.&lt;/p&gt;

&lt;p&gt;And two, one of the directors there saw my friend and me using our knowledge to help others, unblock them, and move our cause for being there- forward.&lt;/p&gt;

&lt;p&gt;So along the line, he pitched an idea he was working on and asked if I would like to be a part of the developers on it. After a few deliberations, I jumped on that opportunity, the rest, they say? is history ...but that's the not the whole story...&lt;/p&gt;

&lt;p&gt;I've been struggling to pickup software development since 2019&lt;/p&gt;

&lt;p&gt;Year in, Year out, after a month or two, I'd always drop it. This time was different. I've stuck with it for over 3 months and counting. It's getting interesting with each day passing and I don't see myself stopping anytime soon.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwv8h8f00pz4ibbxtl8vw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwv8h8f00pz4ibbxtl8vw.png" alt="I didn't know how to use Github in April till June"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How I did this is story for another day.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>learning</category>
      <category>productivity</category>
      <category>tips</category>
    </item>
    <item>
      <title>Id or UUID: Which one should you use as the primary key in your DB?</title>
      <dc:creator>danielAsaboro</dc:creator>
      <pubDate>Fri, 14 Jul 2023 13:35:47 +0000</pubDate>
      <link>https://forem.com/danielasaboro/security-isnt-all-rosy-what-i-learnt-from-participating-in-treblle-api-hackathon-1kok</link>
      <guid>https://forem.com/danielasaboro/security-isnt-all-rosy-what-i-learnt-from-participating-in-treblle-api-hackathon-1kok</guid>
      <description>&lt;p&gt;Carrying a successful attack on a highly-valued asset like the United States of America's President is pretty easy (and that's a big call) — but only if:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You know the exact place, time, and speed of the president's convoy&lt;/li&gt;
&lt;li&gt;which of The Beast the President would be sitting in, and what he will be doing at that time.&lt;/li&gt;
&lt;li&gt;the president's itinerary for the day, the security protocols in place, and his security team's usual habits etc&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Okay, that's enough masterclass in terrorism 💀
&lt;/h3&gt;

&lt;p&gt;What do all these shenanigans got to do with Web development and API Security, you ask? Well, it's pretty simple: A predictable system is inherently insecure.&lt;/p&gt;

&lt;p&gt;This is why you are advised not to encrypt your user's password and instead asked to not just hash them, but also salt them.&lt;/p&gt;

&lt;p&gt;So it wasn't a thing of surprise when I saw that using UUID instead of plain old sequential Ids was one of the things on &lt;a href="https://blog.treblle.com/api-security-hackathon/#:~:text=Monitoring%20with%20Treblle-,Use%20UUIDs%20not%20IDs,-Method%20Limiting"&gt;Treblle API security Hackathon&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3yyrj3js--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/17t46ikjfqpyc9y30csg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3yyrj3js--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/17t46ikjfqpyc9y30csg.png" alt="Excerpt From Trebble's blog" width="719" height="583"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Just as a predictable system can be easily exploited in an attack on a public figure, a predictable system in the digital realm can be targeted by malicious actors — exposing sensitive information and jeopardizing the integrity of the entire system.&lt;/p&gt;

&lt;h2&gt;
  
  
  But there's a problem...
&lt;/h2&gt;

&lt;p&gt;Implementing robust security measures to enhance the resilience of systems and reduces the risk of unauthorized access or exploitation doesn't come all rosy.&lt;/p&gt;

&lt;p&gt;Let's take the use of UUID instead of plain sequential Id (ObjectId in MongoDb), for example. Yes, they have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Universal Uniqueness. &lt;/li&gt;
&lt;li&gt;Independence from central coordination.&lt;/li&gt;
&lt;li&gt;Reduced risk of ID collision.&lt;/li&gt;
&lt;li&gt;Flexibility and interoperability.&lt;/li&gt;
&lt;li&gt;Future-proofing, scalability, and all the good stuff...&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But at what cost?...&lt;/p&gt;

&lt;h3&gt;
  
  
  Is it their Sheer length?
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BY693KgE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5dkdni77q1jhslan2rop.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BY693KgE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5dkdni77q1jhslan2rop.png" alt="Confused" width="480" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;They can be so long that they take up half of my database column or API payload. I'm just trying to store or transmit a simple identifier, but no, I have to deal with this monstrous string that seems to go on forever. It's not only inconvenient but also wastes valuable storage and network bandwidth.&lt;/p&gt;

&lt;h3&gt;
  
  
  Let's talk about Debugging
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--D5NJDok2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1od1objazn4y38hgd77i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--D5NJDok2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1od1objazn4y38hgd77i.png" alt="Debugging Pain" width="640" height="512"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When an issue arises, and I need to dive into my database or logs to find the problematic record, I'm used to quickly identifying it based on its ID. But with UUIDs, I need to copy-paste that monstrosity and hope I don't make any mistakes. Good luck finding that needle in a haystack of cryptic strings.&lt;/p&gt;

&lt;h3&gt;
  
  
  On Performance
&lt;/h3&gt;

&lt;p&gt;Generating a UUID takes significantly more computational resources compared to simply incrementing a sequential ID. So if I'm dealing with a high-throughput system or a massive number of records, the overhead of UUID generation starts to become a real bottleneck.&lt;/p&gt;

&lt;p&gt;Oh, and don't even get me started on sorting or indexing UUIDs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--q7-ZapPz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vnm3mhfxm1sesk4cuxnx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--q7-ZapPz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vnm3mhfxm1sesk4cuxnx.png" alt="Slow Performance" width="480" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With sequential IDs, it's a breeze. &lt;/p&gt;

&lt;p&gt;I can simply order them by their values, and voila! &lt;/p&gt;

&lt;p&gt;But with UUIDs, it's like trying to solve a complex puzzle. I have to resort to weird sorting algorithms, convert them to binary representations, or split them into multiple columns just to make them somewhat sortable. &lt;/p&gt;

&lt;p&gt;It's a nightmare for anyone who values simplicity and efficiency.&lt;/p&gt;

&lt;p&gt;UUID have their benefits, but the tradeoffs are real.&lt;/p&gt;

&lt;h2&gt;
  
  
  But don't get me wrong!
&lt;/h2&gt;

&lt;p&gt;Although predictability is an open invitation for attacks and the element of surprise can transform into stronghold — Not all scenarios require or benefit from complete unpredictability.&lt;/p&gt;

&lt;p&gt;Remember, when it comes to human-facing interfaces, intuitive and memorable IDs are crucial for a good user experience. &lt;/p&gt;

&lt;p&gt;Users should be able to easily identify and remember entities or items based on their IDs. This is especially important in applications where users need to reference or communicate about specific items frequently.&lt;/p&gt;

&lt;p&gt;And most applications like E-commerce Platforms, CMS (Content Management Systems), and Data Analytics platforms have specific sorting and indexing needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  There's no one-size-fits-all solution.
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sdf8QJZE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/14xiq6n4n5fy9lq6exz4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sdf8QJZE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/14xiq6n4n5fy9lq6exz4.png" alt="One size fit all problem" width="480" height="362"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Your choice should be driven your application requirements, specific needs, and the trade-offs you are willing to take on.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Evaluate them.&lt;/li&gt;
&lt;li&gt;Consider the benefits.&lt;/li&gt;
&lt;li&gt;And Weigh the Limitations.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's the only way to make an informed decision. And this is the goal of this article. &lt;/p&gt;

&lt;h3&gt;
  
  
  ⚠️⚠️ A big Note ⚠️⚠️
&lt;/h3&gt;

&lt;p&gt;Throughout history, attacks on public figures, including heads of state, have unfortunately occurred. It is important to note that discussing these incidents should not be seen as endorsing or promoting violence.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>database</category>
      <category>security</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
