<?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>DEV Community: proflupin.solᵍᵐ 🐍</title>
    <description>The latest articles on DEV Community by proflupin.solᵍᵐ 🐍 (@0xprof_lupin).</description>
    <link>https://dev.to/0xprof_lupin</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%2F938853%2F897273a3-e1b1-4b1a-894c-673cfcddd5c8.jpg</url>
      <title>DEV Community: proflupin.solᵍᵐ 🐍</title>
      <link>https://dev.to/0xprof_lupin</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/0xprof_lupin"/>
    <language>en</language>
    <item>
      <title>A dummy's guide to Solana's architecture</title>
      <dc:creator>proflupin.solᵍᵐ 🐍</dc:creator>
      <pubDate>Wed, 12 Oct 2022 07:13:02 +0000</pubDate>
      <link>https://dev.to/0xprof_lupin/a-dummies-guide-to-solana-2ije</link>
      <guid>https://dev.to/0xprof_lupin/a-dummies-guide-to-solana-2ije</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;This tutorial is meant to be for a spectrum of readers:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Those experienced in the EVM space&lt;/li&gt;
&lt;li&gt;Those new to web3&lt;/li&gt;
&lt;li&gt;Non-developers&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We will be going through some of the core concepts in the Solana architecture. These are basic building blocks for every action that happens on this chain. The concepts we are going to discuss are not only beneficial to understand for aspiring developers but also for end users to make the most out of the experience of fast and cheap transactions on Solana.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Block Explorer: a window to the chain
&lt;/h3&gt;

&lt;p&gt;Block explorers are online interfaces which provide the user a chance to search, and retrieve data points for past and on-going transactions, wallet addresses and other useful info on a given chain. This provides a dimensionality of transparency between the chain and the users.&lt;/p&gt;

&lt;p&gt;There are several pretty decent block explorers on Solana:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://explorer.solana.com/"&gt;Official Solana Explorer&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://solscan.io/"&gt;Solscan&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://solanabeach.io/"&gt;Solana Beach&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blockchair.com/solana"&gt;Blockchair&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://solana.fm/"&gt;SolanaFM&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--idRn_wB---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r0f8va8pja9jgw1xnu95.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--idRn_wB---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r0f8va8pja9jgw1xnu95.png" alt="Image description" width="880" height="549"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Throughout the tutorial, we'll see examples right from the block explorers that juxtapose the theory we discuss. Here are some of the words you'll see often throughout the tutorial:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Blocks, Validators and Proof of History!&lt;/li&gt;
&lt;li&gt;Accounts&lt;/li&gt;
&lt;li&gt;Instructions and Transactions&lt;/li&gt;
&lt;li&gt;Programs&lt;/li&gt;
&lt;li&gt;Token Program&lt;/li&gt;
&lt;li&gt;Token Metadata Program&lt;/li&gt;
&lt;li&gt;Program Derived Addresses (PDA)&lt;/li&gt;
&lt;li&gt;SPL-tokens, Fungible Assets and Non-Fungible Tokens (NFTs)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's start from the very top. What the hell even is a blockchain?&lt;/p&gt;




&lt;h2&gt;
  
  
  Blocks, Validators and Proof of History:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EJ2eurlm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eew1z489grqv0o9t6i7h.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EJ2eurlm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eew1z489grqv0o9t6i7h.jpeg" alt="blockchain" width="880" height="588"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Without going into the depths of the jargon ocean, a blockchain is simply a digitally distributed database. The key difference between a typical database and a blockchain is how the stored data is structured.&lt;/p&gt;

&lt;p&gt;A blockchain stores and manages data into small groups known as Blocks. A block usually stores important information like input and output hashes, number of transactions, and the event it contains. When a block is filled with data or "created", by a blockchain node, it is linked to the previous blocks. This forms a chain of blocks, or a blockchain.&lt;/p&gt;

&lt;p&gt;In the case of Solana, when a node claims to have created a block, the other nodes strive to verify this claim. The node that generated to block is known as the &lt;strong&gt;Leader&lt;/strong&gt; and the nodes that verify the claim are known as &lt;strong&gt;Validators&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;How does this validation, or consensus work on Solana? &lt;strong&gt;Proof of History (PoH)&lt;/strong&gt;&lt;/p&gt;

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

&lt;blockquote&gt;
&lt;p&gt;This is exactly what makes Solana unique. Its extremely easy, fast and cheap-to-use nature allows itself to be named the world's first web-scale blockchain. The underlying technology behind Solana is the novel consensus mechanism known as Proof of History.&lt;/p&gt;

&lt;p&gt;"Proof of History is exactly what the name suggests: a proof of historical events", Anatoly Yakovenko.&lt;/p&gt;

&lt;p&gt;PoH is a SHA-256 hashed, verifiable delay function (VDF): this function guarantees the following: when the output hash is validated for an input hash, it is by the nature of PoH that we can confirm that some time has passed since we provided the input. This very nature of the VDFs insures the super fast speeds of the Solana blockchain.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Coming back to how &lt;strong&gt;Validators&lt;/strong&gt; prove that the &lt;strong&gt;Leader&lt;/strong&gt; node is the node that generated the block: the &lt;strong&gt;Validators&lt;/strong&gt; run the above &lt;strong&gt;PoH VDF&lt;/strong&gt; on a number of transactions existing on the block to be verified. The outputs of the VDF are then compared with the outputs provided by the &lt;strong&gt;Leader&lt;/strong&gt; node. Once proven, the Leader is then confirmed to have created the block and rewards for validation are distributed to all the validators, including the Leader.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VlA5F88y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/egcwo3s9emyxcjrids37.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VlA5F88y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/egcwo3s9emyxcjrids37.png" alt="Image description" width="880" height="534"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above view of a given block #154616344, we can see a variety of information.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Block Hash&lt;/strong&gt;: The SHA-256 hash (reference number) for a given block on chain.&lt;br&gt;
&lt;strong&gt;Leader&lt;/strong&gt;: The block hash of the node that created the given block.&lt;br&gt;
&lt;strong&gt;Previous Block Hash&lt;/strong&gt;: The parent block's # of the given block.&lt;br&gt;
&lt;strong&gt;Reward&lt;/strong&gt;: The total rewards distributed to the Validators.&lt;br&gt;
&lt;strong&gt;Transactions&lt;/strong&gt;: The total number of transactions (successful + unsuccessful) executed in the given block.&lt;/p&gt;

&lt;p&gt;Now, if you click on one of the hashes in the &lt;strong&gt;By&lt;/strong&gt; column of the &lt;strong&gt;Transactions&lt;/strong&gt; section, we land on a page which gives a detailed overview of the Account with hash &lt;a href="https://solscan.io/account/GFDmfhoPtZZATNxw8zyZPVYKkBZutf1zoZTbRbxDjh5E"&gt;GFDmfhoPtZZATNxw8zyZPVYKkBZutf1zoZTbRbxDjh5E&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FKwavwFh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/96rdkpxvrpjibrfcfbjl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FKwavwFh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/96rdkpxvrpjibrfcfbjl.png" alt="Image description" width="880" height="498"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let us first go through some theory and after which we can truly understand the account page and all its components.&lt;/p&gt;


&lt;h2&gt;
  
  
  Accounts
&lt;/h2&gt;

&lt;p&gt;Solana's &lt;strong&gt;Account model&lt;/strong&gt; is very unique and is partially responsible for why its so damn fun to build apps on it.&lt;/p&gt;

&lt;p&gt;On any blockchain, decentralised apps need to track the current state: number of tokens, NFTs transferred, current highest bidder in an auction, orders for a token on a DEx etc. These states need to be saved in data storing units on-chain, called &lt;code&gt;accounts&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;On EVM, smart contracts are executable pieces of code or programs. They are accounts themselves and store their own data. The code inside the smart contract defines how the data within the account is going to be modified. &lt;/p&gt;

&lt;p&gt;On Solana, &lt;strong&gt;Accounts&lt;/strong&gt; and on-chain programs interact differently. On-chain executable programs are stored in &lt;strong&gt;completely immutable&lt;/strong&gt; accounts, whereas data that the executable programs interact with is stored in &lt;strong&gt;mutable&lt;/strong&gt; accounts.&lt;/p&gt;

&lt;p&gt;All accounts on Solana are assigned a &lt;strong&gt;Program&lt;/strong&gt; as the &lt;strong&gt;owner&lt;/strong&gt;, and only these owners are allowed to make changes to the data (or debit Solana) from a given account. Important to note here: anyone can credit funds permissionless-ly to an account.&lt;/p&gt;

&lt;p&gt;A developer coming from the EVM space might find this state-less Account Model to be a little confusing and complex. But this model allows something which is not possible in other chains: &lt;strong&gt;Transaction parallelisation&lt;/strong&gt;. We are going to talk more about this in the  following section.&lt;/p&gt;

&lt;p&gt;On Solscan's page for account &lt;code&gt;GFDmfhoPtZZATNxw8zyZPVYKkBZutf1zoZTbRbxDjh5E&lt;/code&gt;, we can see that the account holds some SOL and has some tokens. We'll discuss what tokens are later. But for now lets check out the section for &lt;strong&gt;Transactions&lt;/strong&gt;. If you click on any one of the &lt;code&gt;Signatures&lt;/code&gt; of these transactions, we'll land on a new page which shows some Transaction details. But before we dive deep into this, lets understand what transactions are.&lt;/p&gt;


&lt;h2&gt;
  
  
  Instructions and Transactions
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Instructions&lt;/strong&gt; are the basic operational units on Solana. Instructions are commands that can be bundled up together to form &lt;strong&gt;Transactions&lt;/strong&gt;. These transactions can then be executed by a &lt;strong&gt;Program&lt;/strong&gt; to read and/or write data from one or more &lt;strong&gt;Accounts&lt;/strong&gt;. The instructions that form the transaction are executed atomically, or one-by-one in the order in which they were added to form the transaction. If one instruction fails, the entire transaction is invalidated.&lt;/p&gt;

&lt;p&gt;An instruction takes the following data:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;program_id&lt;/code&gt; of the Program which owns the accounts who's states are going to change&lt;/li&gt;
&lt;li&gt;Array of all &lt;code&gt;accounts&lt;/code&gt; the instruction intends to read/write data from.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;instruction_data&lt;/code&gt; array which specifies more metadata intended for the program &lt;code&gt;program_id&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;One of more of such instructions are then bundled to form the transaction which needs to specify the following data before it can be executed:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Array of all &lt;code&gt;accounts&lt;/code&gt; it intends to read/write data from.&lt;/li&gt;
&lt;li&gt;The array of all &lt;code&gt;instructions&lt;/code&gt; the transaction wants to specify in the very same order the user wants to execute them&lt;/li&gt;
&lt;li&gt;A recent &lt;code&gt;blockhash&lt;/code&gt;: this is required to prevent duplication and stale transactions. The max age of transaction is 150 blocks.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;signatures&lt;/code&gt; of all accounts the given transaction intends to debit from or to write data into. This signature array needs to be in the same order of the corresponding accounts in the &lt;code&gt;accounts&lt;/code&gt; array.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;While we are talking about transactions, its important to also talk about the Transactions per Second (TPS) of the network. Solana is famed to have one of the highest TPS on any chain. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Sd4BP8T3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e4ufaye8c35728abg1j8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Sd4BP8T3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e4ufaye8c35728abg1j8.png" alt="vote vs non-vote" width="880" height="757"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are two types of transactions &lt;strong&gt;Vote&lt;/strong&gt; and &lt;strong&gt;Non-Vote&lt;/strong&gt; transactions. Vote transactions are used to do the network validation as described in the Proof of History section, and hence are not the "true" transactions being utilised for doing the actual work on chain like transferring NFTs / tokens, bidding, selling etc. The graph above shows that in the last 7 days, number of Vote transactions are almost 7 times as much as the Non-Vote transactions. This plays into the true &lt;strong&gt;TPS (Transactions per Second)&lt;/strong&gt; debate of Solana: although Solana is blazingly fast with reported TPS touching averaging &amp;gt;3k, the true TPS (removing transactions for Voting) is &amp;lt;1.5K.&lt;/p&gt;

&lt;p&gt;Now that we know what transactions and instructions are, we ought to understand who actually triggers/interacts with them. The answer is &lt;strong&gt;Programs&lt;/strong&gt;.&lt;/p&gt;


&lt;h2&gt;
  
  
  Programs
&lt;/h2&gt;

&lt;p&gt;We have mentioned &lt;strong&gt;Programs&lt;/strong&gt; quite a lot of times in this tutorial. But what exactly are &lt;strong&gt;Programs&lt;/strong&gt;?&lt;/p&gt;

&lt;p&gt;You might have heard of &lt;strong&gt;Smart Contracts&lt;/strong&gt; in other chains like EVM. The equivalent to the smart contracts on Solana are &lt;strong&gt;Programs&lt;/strong&gt;. Programs are nothing but executable code that is stored in completely immutable Accounts marked as &lt;code&gt;executable&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;The way Programs differ from Smart Contracts is that Programs on Solana are state-less, ie, they do not store the data that they are processing / acting on. Data and code that processes the data are stored in different accounts. This allows the processing of data in a parallel fashion: multiple programs can reuse the same data in specific accounts for different purposes, in different transactions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--l0jUCsyn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v166us9xxba8yujdrp5v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--l0jUCsyn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v166us9xxba8yujdrp5v.png" alt="analogy" width="880" height="954"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can imagine this parallelisation to be something similar to how functions in programming work: Variables can be defined to store some data. These variables can then be passed as reference to multiple instances of the same function or different functions asynchronously to make changes to these variables. In this analogy, the variables are &lt;strong&gt;Accounts&lt;/strong&gt; and the functions are &lt;strong&gt;Programs&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Coming back to the &lt;a href="https://solscan.io/tx/3bsfEaCdbjcBvXQT3Fx85R2TvKL3KJe5kb4G8XYqUFXCBxKzemu6FV3fi2C51TBtcKpjygCfzdXsjg9dTjVxpEo5"&gt;Solscan page&lt;/a&gt; for a transaction with signature &lt;code&gt;3bsfEaCdbjcBvXQT3Fx85R2TvKL3KJe5kb4G8XYqUFXCBxKzemu6FV3fi2C51TBtcKpjygCfzdXsjg9dTjVxpEo5&lt;/code&gt;, we can start to understand what its trying to tell us.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--G6gj-DLv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ozfgo4r8muyvek5glknf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--G6gj-DLv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ozfgo4r8muyvek5glknf.png" alt="tx overview" width="880" height="335"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the transaction overview, we can checkout the block in which the transaction was executed, the fee to run the transaction, whether the transaction was successful or not and most importantly, the main actions that the transaction executes. In this case, there was a transfer of 253 SOL from wallet &lt;a href="https://solscan.io/account/GFDmfhoPtZZATNxw8zyZPVYKkBZutf1zoZTbRbxDjh5E"&gt;&lt;code&gt;GFDmfhoPtZZATNxw8zyZPVYKkBZutf1zoZTbRbxDjh5E&lt;/code&gt;&lt;/a&gt; to &lt;a href="https://solscan.io/account/4tzAkc7cGTns1dsVaP18KvMkt9jEmzA1AaV3rMzgyi7f"&gt;&lt;code&gt;4tzAkc7cGTns1dsVaP18KvMkt9jEmzA1AaV3rMzgyi7f&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rMmdCAa8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4wkwnwj7oyc2c62uemea.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rMmdCAa8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4wkwnwj7oyc2c62uemea.png" alt="tx ix detail" width="880" height="214"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can also see the same on the instruction detail. In the given transaction, only 1 instruction was executed. As it was a simple SOL transfer, the program which interacts with the transaction is the &lt;code&gt;System Program&lt;/code&gt;, with hash: &lt;a href="https://solscan.io/account/11111111111111111111111111111111"&gt;&lt;code&gt;11111111111111111111111111111111&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If we go back to the &lt;a href="https://solscan.io/account/GFDmfhoPtZZATNxw8zyZPVYKkBZutf1zoZTbRbxDjh5E#tokenAccounts"&gt;Account page&lt;/a&gt; on Solscan, we can see a section for &lt;strong&gt;Token Accounts&lt;/strong&gt;, and also see some &lt;strong&gt;SPL-tokens&lt;/strong&gt; listed. Let us see what these are.&lt;/p&gt;


&lt;h2&gt;
  
  
  SPL-tokens, NFTs and the Token Program
&lt;/h2&gt;

&lt;p&gt;Like any other blockchain, Solana has tokens as well. These are assets that exist on-chain and can be traded from person to person or through secondary marketplaces. These tokens fuel several use-cases to the blockchain technology like DeFi and are important for retail adoption of the crypto-economy.&lt;/p&gt;

&lt;p&gt;All tokens on Solana follow &lt;a href="https://spl.solana.com/token"&gt;Solana's Token Program&lt;/a&gt; and &lt;a href="https://docs.metaplex.com/programs/token-metadata/token-standard"&gt;Metaplex's Token Metadata Standard&lt;/a&gt;. Let us see how these programs play together to form different tokens on Solana.&lt;/p&gt;


&lt;h2&gt;
  
  
  Token Program
&lt;/h2&gt;

&lt;p&gt;Solana's Token program is responsible for defining the common implementation for all tokens on Solana. &lt;/p&gt;

&lt;p&gt;The &lt;code&gt;spl-token-cli&lt;/code&gt; is a part of the Token program and allows the generation of tokens using command line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;spl-token create-token
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can follow the &lt;a href="https://spl.solana.com/token#reference-guide"&gt;following&lt;/a&gt; reference guide to play around with the CLI but we won't go too deep into the specifics in this tutorial.&lt;/p&gt;

&lt;p&gt;To fully understand how tokens work on Solana, its important to understand the account model of the Token program.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Bvvwa5YP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7yttg7xmt5275t0ptlmt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Bvvwa5YP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7yttg7xmt5275t0ptlmt.png" alt="token program" width="880" height="204"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the image above we can see 3 accounts: &lt;code&gt;Wallet Account&lt;/code&gt;, &lt;code&gt;Token Account&lt;/code&gt; and the &lt;code&gt;Mint Account&lt;/code&gt;. The &lt;code&gt;Wallet Account&lt;/code&gt; is owned by the native &lt;code&gt;System Program&lt;/code&gt; and represents a user's wallet. The &lt;code&gt;Token Account&lt;/code&gt; and the &lt;code&gt;Mint Account&lt;/code&gt; are owned by the &lt;code&gt;Token Program&lt;/code&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;Mint Account&lt;/code&gt; is responsible for storing global information regarding the Token, like current supply, &lt;code&gt;Authority&lt;/code&gt; (the account address which has the authority to make changes to the given Account), token name, decimals, number of holders etc.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;Token Account&lt;/code&gt; is responsible for storing the relationship between the &lt;code&gt;Wallet Account&lt;/code&gt; and the &lt;code&gt;Mint Account&lt;/code&gt;, ie, it stores data like the number of tokens held by the wallet etc.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  Associated Token Account Program
&lt;/h3&gt;

&lt;p&gt;While discussing Token Accounts, its important to mention about the &lt;strong&gt;&lt;a href="https://spl.solana.com/associated-token-account"&gt;Associated Token Accounts&lt;/a&gt;&lt;/strong&gt;. Why are these needed?&lt;/p&gt;

&lt;p&gt;There can be more than 1 token accounts for a given token in a wallet. When a user sends a token from wallet A to wallet B, the user does not know which token account to specify as the destination token account. To solve this problem, associated token accounts are used to deterministically derive a token account address from a user's &lt;strong&gt;System Account&lt;/strong&gt; (wallet), and the mint address. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;While the &lt;code&gt;Mint Account&lt;/code&gt; stores some global information regarding tokens, it is not capable of storing enough data to be able to be standardised and used globally by dapps and wallets. Here's where Metaplex's Token Metadata Program comes in.&lt;/p&gt;




&lt;h2&gt;
  
  
  Token Metadata Program
&lt;/h2&gt;

&lt;p&gt;Its main goal is to attach additional data to all tokens on Solana. This allows to have a standardised way to read and observe tokens on wallets, dapps, and even block explorers which further allows the user experience to be uniform across the ecosystem.&lt;/p&gt;

&lt;p&gt;The Metadata program uses &lt;strong&gt;PDAs&lt;/strong&gt; to achieve this.&lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  Program Derived Addresses (PDAs)
&lt;/h3&gt;

&lt;p&gt;When we discussed &lt;strong&gt;Accounts&lt;/strong&gt;, we talked about the need for the account's owner to sign transactions whenever a program makes a change to the said account. &lt;/p&gt;

&lt;p&gt;This is problematic and not always possible. Imagine a use-case where we are counting the number of tokens in a given account and this number needs to be saved on-chain. The account's owner will have to sign transactions each time this number changes.&lt;/p&gt;

&lt;p&gt;An ingenious solution to this is PDAs. PDAs envelop accounts that can be programmatically controlled by certain programs. This allows programs to sign on behalf of these accounts without a requirement of a private key, as shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KMt9N6Ff--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/beq9tz6ed33ohrhm9plb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KMt9N6Ff--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/beq9tz6ed33ohrhm9plb.png" alt="PDAs" width="880" height="627"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;PDAs are deterministically derived from a &lt;code&gt;program_id&lt;/code&gt; and a string (also known as seeds) like &lt;code&gt;"auction_house"&lt;/code&gt; or &lt;code&gt;"token_metadata"&lt;/code&gt;. If you want to dive deep into how PDAs are generated, I highly recommend reading &lt;a href="https://solanacookbook.com/core-concepts/pdas.html#generating-pdas"&gt;Solana Cookbook's PDA guide&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The Token Metadata Program attaches an account known as &lt;strong&gt;Metadata Account&lt;/strong&gt; with the &lt;strong&gt;Mint Account&lt;/strong&gt; using a PDA as shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xD6X5AIg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z0ss6xd0vsrl3wrqvoub.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xD6X5AIg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z0ss6xd0vsrl3wrqvoub.png" alt="token metadata program" width="880" height="545"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This account stores a lot of useful information that adds a whole new dimensionality to tokens on Solana, that the Token Program could not provide. This account also has a &lt;code&gt;URI&lt;/code&gt; field which points to an off-chain JSON object. This object saves information like image, attributes for an NFT etc and helps even further enrich the token with data.&lt;/p&gt;

&lt;p&gt;The combination of the &lt;code&gt;Token Program&lt;/code&gt; and the &lt;code&gt;Token Metadata Program&lt;/code&gt; allows tokens to be categorised into three broad categories depending on two characteristics:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;supply&lt;/code&gt;: the total number of tokens in circulation.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;decimal places&lt;/code&gt;: the number of decimals points a token is allowed to have. For example: SOL is allowed to have 9 decimal points, which means, 10^-9 SOL is a valid denomination and can be transferred between wallets.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Qym6vjZ7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f3016473mth2upuedzom.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Qym6vjZ7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f3016473mth2upuedzom.png" alt="different types of tokens" width="880" height="498"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  SPL-tokens
&lt;/h2&gt;

&lt;p&gt;These tokens are based on the &lt;a href="https://spl.solana.com/"&gt;Solana Program Library (SPL)&lt;/a&gt; and are supported by SOL the same way ERC-20 tokens are supported by ETH: the transaction fees for transferring these tokens from 1 account to another is paid in the native currency, SOL in the case of the Solana chain. &lt;/p&gt;

&lt;p&gt;SPL-tokens and their associated metadata can be generated on the CLI using &lt;a href="https://metaboss.rs/create.html"&gt;Metaboss&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;metaboss create fungible -d &amp;lt;decimals&amp;gt; -m &amp;lt;metadata_file&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What sets the SPL-tokens apart are their characteristic of having:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;supply&lt;/code&gt; &amp;gt; 1&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;decimal places&lt;/code&gt; &amp;gt; 0&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Fungible assets
&lt;/h2&gt;

&lt;p&gt;Fungible assets are tokens that have:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;supply&lt;/code&gt; &amp;gt; 1&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;decimal places&lt;/code&gt; = 0&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Having a supply greater than 1 but decimal places equal to 0 creates tokens that have very unique use-cases: gaming assets or utilities like a shield or a piece of wood. These assets with decimals equal to 0 can't be divided or fractionalised but are non-singular in supply, thus allowing distribution to a number of users.&lt;/p&gt;




&lt;h2&gt;
  
  
  Non-Fungible tokens (NFTs)
&lt;/h2&gt;

&lt;p&gt;These tokens are the ones which have gained a lot of traction in this past year. NFTs are are tokens that are non-replaceable / interchangeable. What this means is that there can not be more than 1 specimen of a given token. Every token is unique and can't be fractionalised. Here are their properties:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;supply&lt;/code&gt; = 1&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;decimal places&lt;/code&gt; = 0&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;NFTs are usually represented by a visual asset: it could either be an image, video or gif. The asset could also be an mp3 file thus allowing the possibilities of music NFTs.&lt;/p&gt;

</description>
      <category>solana</category>
      <category>web3</category>
      <category>blockchain</category>
      <category>nfts</category>
    </item>
  </channel>
</rss>
