<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by OpenDevICON on Medium]]></title>
        <description><![CDATA[Stories by OpenDevICON on Medium]]></description>
        <link>https://medium.com/@opendevicon?source=rss-a809fbf2775c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ao2p4Dh55zXp4PPyKBQv7A.png</url>
            <title>Stories by OpenDevICON on Medium</title>
            <link>https://medium.com/@opendevicon?source=rss-a809fbf2775c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 12:52:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@opendevicon/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Token SCORE Factory — A Token Generator for ICON]]></title>
            <link>https://medium.com/opendevicon/tsf-introduction-5f7f0ec96f43?source=rss-a809fbf2775c------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f7f0ec96f43</guid>
            <category><![CDATA[token-score-factory]]></category>
            <category><![CDATA[opendevicon]]></category>
            <category><![CDATA[token]]></category>
            <category><![CDATA[icon-foundation]]></category>
            <category><![CDATA[icx]]></category>
            <dc:creator><![CDATA[OpenDevICON]]></dc:creator>
            <pubDate>Thu, 10 Jun 2021 08:13:55 GMT</pubDate>
            <atom:updated>2021-07-13T10:30:23.905Z</atom:updated>
            <content:encoded><![CDATA[<p>A token is a digital asset on a blockchain that runs on a smart contract. Creating a token includes different steps like deploying a new smart contract, deciding token supply, enabling token transaction, setting the token’s name, symbol, and decimal units, creating a token transfer event, etc. This process can be a huge obstacle for users with no prior coding knowledge.</p><h3><strong>What is Token SCORE Factory?</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sBOhLlLEy9chk9XbkwwDPg.png" /></figure><p><a href="http://tsf.opendevicon.io/"><strong>Token Score Factory (TSF)</strong></a><strong> is a web platform on the ICON blockchain where anyone can create IRC-2 &amp; IRC-3 SCORE from their browser without writing a single line of code.</strong> The <a href="https://github.com/icon-project/IIPs/blob/master/IIPS/iip-2.md">IRC-2</a> token on ICON is the standard token equivalent to the ERC-20 token on Ethereum which is used for fungible tokens. Similarly, <a href="https://github.com/icon-project/IIPs/blob/master/IIPS/iip-3.md">IRC-3</a> is the equivalent standard token of ERC-721, also used for NFTs (Non-Fungible Tokens).</p><p>Users can simply provide details on what kind of token they want and TSF deploys Token without users having to set the necessary development environment. Token SCORE Factory is a grant-driven program to reduce the hurdle to develop tokens and deploy them. The platform can be used to deploy production-grade smart contracts into the mainnet. It can also be used to experiment with different SCORE options at a minimal cost.</p><p>The extensions for IRC2 and IRC3 which can be created on TSF are as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*PEgn_6hIUp780a74MqlA7g.png" /></figure><h3><strong>How to use Token SCORE Factory</strong></h3><p>Prerequisite: To use it, you need to have a Ledger or <a href="https://chrome.google.com/webstore/detail/iconex/flpiciilemghbmfalicajoolhkkenfel?hl=en">ICONex</a> account.</p><p>Visit —<a href="https://tsf.opendevicon.io/create"> Token SCORE Factory</a></p><p>Basic IRC2 token allows limited functionality, only the functions specified in IIP2 standard. You can give the name, symbol, decimals, and initial supply. Once these parameters are given, they cannot be changed even on updating the contract.</p><p>All the tokens will be minted at the deployer wallet. The deployer can then transfer the tokens to other wallets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bLIZPcQFhE9pEGr7" /></figure><p>Now, you can select where to deploy the contract to, to testnet, or mainnet via a dropdown under this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*68wIS7aoCBT710vm" /></figure><p>Now, after accepting the terms of use, you can create tokens. After the contract deployment is successful, you’ll get an initial supply amount of tokens in your wallet for the respective pre-defined testnet/mainnet.</p><p>Similarly, for other extensions of IRC2 and IRC3 tokens, you provide the required parameters like name, symbol, initial supply, total supply, etc, and press on ‘deploy the contract’. Once the contract is deployed, you can perform token transfer operations via ICONex or <a href="https://yudus.dev/icontracthub/">yudus.dev</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f7f0ec96f43" width="1" height="1" alt=""><hr><p><a href="https://medium.com/opendevicon/tsf-introduction-5f7f0ec96f43">Token SCORE Factory — A Token Generator for ICON</a> was originally published in <a href="https://medium.com/opendevicon">OpenDevICON</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Token SCORE Factory: Token Extensions]]></title>
            <link>https://medium.com/opendevicon/tsf-token-extensions-4e4be8f846b4?source=rss-a809fbf2775c------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e4be8f846b4</guid>
            <category><![CDATA[icon-foundation]]></category>
            <category><![CDATA[token-score-factory]]></category>
            <category><![CDATA[icx]]></category>
            <category><![CDATA[opendevicon]]></category>
            <category><![CDATA[token]]></category>
            <dc:creator><![CDATA[OpenDevICON]]></dc:creator>
            <pubDate>Thu, 10 Jun 2021 08:11:39 GMT</pubDate>
            <atom:updated>2021-06-10T08:18:42.511Z</atom:updated>
            <content:encoded><![CDATA[<p>Users can deploy <a href="https://github.com/icon-project/IIPs/blob/master/IIPS/iip-2.md">IRC-2</a> and <a href="https://github.com/icon-project/IIPs/blob/master/IIPS/iip-3.md">IRC-3</a> tokens on ICON fromToken SCORE Factory. Users can enter the parameters in the creation form and once the transaction is confirmed, the selected token is created without users having to write a single line of code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lJ47ssQ3Js-8NgkdTN8xWA.png" /></figure><p>Different extensions of IRC-2 and IRC-3 tokens can be deployed from TSF, but before that let’s look at some of the common terms of a token :</p><ul><li><strong>Mintable</strong></li></ul><p>A mintable token can be minted out of thin air. However, in the IRC-2 contract, only the deployer can mint IRC-2 tokens whereas, in IRC-3 contracts, there are two options for minting. First where only the deployer can mint NFTs, and other, where anyone can mint NFTs.</p><ul><li><strong>Burnable</strong></li></ul><p>A Burnable token means that the token can be destroyed. In both cases of IRC-2 and IRC-3, token holders can burn their tokens. In the case of IRC-3, no one can burn anyone else’s token unless it’s approved by the user.</p><ul><li><strong>Pausable</strong></li></ul><p>It can be used to prevent any token operations, transfer, mint, and burn. This allows the deployer to fix any bugs in smart contracts or in ICOs. This is implemented in IRC2 only.</p><ul><li><strong>Capped</strong></li></ul><p>It is used to limit the number of tokens that can be minted. It is defined while deploying mintable IRC2 contracts. When it is not specified, it defaults to the maximum amount of tokens that can be minted, given by 2**256 -1.</p><ul><li><strong>Token Recovery</strong></li></ul><p>Token Recovery allows the SCORE owner to recover the IRC2 tokens sent to other SCORES, provided they have a fallback mechanism in place. It is implemented in Complete IRC2.</p><ul><li><strong>Snapshot</strong></li></ul><p>It allows us to view the balance of an account and total supply at a particular block height. It’s implemented in the Complete IRC2 token.</p><ul><li><strong>Approval</strong></li></ul><p>It allows a token owner to approve a token to someone else. Once someone is approved, then that user will be allowed to use the token on behalf of the owner. It is available for IRC3 tokens only.</p><ul><li><strong>TokenURI</strong></li></ul><p>TokenURI is metadata for an IRC3 token. It should resolve to a JSON document that might look something like this:</p><pre><br> {</pre><pre>“name”: “Punk123”,</pre><pre>“description”: “Description..”,</pre><pre>“image”: “&lt;ipfs image url&gt;”,</pre><pre>“rarity”: “2”</pre><pre>}</pre><h3><strong>Extensions for IRC2</strong></h3><ul><li><strong>Basic</strong></li></ul><p>Allows creation of IRC2 as per the ICON IIP2 standard. When an initial supply is given, tokens are transferred to the deployer wallet on contract creation. This token can be later transferred to other addresses.</p><ul><li><strong>Mintable</strong></li></ul><p>Basic + tokens can be minted. Only the deployer can mint the tokens. Users can specify the total number of tokens to be created. If a user fails to enter any amount in total supply, an uncapped token is created.</p><ul><li><strong>Burnable</strong></li></ul><p>Basic + tokens can be burned. Token holders can burn the tokens they own.</p><ul><li><strong>Pausable</strong></li></ul><p>Basic IRC2 + Token transfer operations can be paused. Only the deployer can pause/unpause the token.</p><ul><li><strong>Mintable+Burnable</strong></li></ul><p>Basic + Mint + burn functionality. Tokens can be minted by the deployer, and token holders can burn them.</p><ul><li><strong>Burnable+Pausable</strong></li></ul><p>Basic + burn + pause. Deployers can pause tokens &amp; token owners can burn their tokens. Tokens cannot be minted and the total supply decreases when tokens are burned.</p><ul><li><strong>Mintable+Burnable+Pausable</strong></li></ul><p>All mint, burn and pause functionality along with basic IRC2 token.</p><ul><li><strong>Complete</strong></li></ul><p>All the previously mentioned functions + token recovery + snapshot. Token recovery can be done from tokens that implement the token fallback mechanism. And it also allows users to view total supply and balance at a specific block height.</p><h3><strong>Extensions for IRC3</strong></h3><ul><li><strong>Mintable</strong></li></ul><p>An extension for the IRC3 token standard along with added minted functionality. It has two further extensions, one where only the deployer can mint new tokens, and the other where any user can mint them. On minting new tokens, there is a parameter called `tokenURI`, which can be supplied. It is the metadata for the token. It ideally is a JSON file, which contains information about the token. For example, on crypto punks, we can link name, and image URL as param in tokenUri. Once TokenURI is set, it cannot be changed later.</p><ul><li><strong>Burnable</strong></li></ul><p>Mintable + burn functionality. It has two further extensions. First, where only the deployer can mint. And the second, where anyone can mint. Token holders can burn their tokens.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e4be8f846b4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/opendevicon/tsf-token-extensions-4e4be8f846b4">Token SCORE Factory: Token Extensions</a> was originally published in <a href="https://medium.com/opendevicon">OpenDevICON</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Icon-BandProtocol Integration]]></title>
            <link>https://medium.com/opendevicon/icon-bandprotocol-integration-a94dacfebf84?source=rss-a809fbf2775c------2</link>
            <guid isPermaLink="false">https://medium.com/p/a94dacfebf84</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[band-protocol]]></category>
            <category><![CDATA[icon-foundation]]></category>
            <category><![CDATA[crosschain]]></category>
            <dc:creator><![CDATA[OpenDevICON]]></dc:creator>
            <pubDate>Thu, 12 Nov 2020 12:37:57 GMT</pubDate>
            <atom:updated>2020-11-12T12:37:57.325Z</atom:updated>
            <content:encoded><![CDATA[<p>Band Protocol is a cross-chain data oracle platform. It allows integration of real world data and APIs to smart contracts. It has recently been gaining prominence in the Oracle space due to its certain design and architecture choices. It is built using the Cosmos sdk and provides cross-chain using IBC. The Oracle Script architecture makes it easy for developers to create custom-made oracles using WebAssembly to connect smart contracts with traditional APIs.</p><p>Band Protocol is already integrated with the ICON platform. Developers on ICON can use the existing integration to get price feeds for ICON native assets such as ICX using the Band’s <em>std_reference</em> SCORE on ICON. More on this can be found <a href="https://www.icondev.io/docs/band-protocol">here</a>. Besides this developers can use any of the Oracle scripts or create custom scripts to provide custom Oracle data to their SCORE in ICON.</p><p>Let us explore how to integrate custom Oracle data for your SCORE.We will explore an example available via ODI here. In this example we are using Band’s Quantum Random Number Generator <a href="https://guanyu-devnet.cosmoscan.io/oracle-script/11">Oracle Script</a> to get a random number from Band. That random number is then used to decide on the winning number for a dice roll for a user. It uses the Bridge contract cxc2685f4bde237b38b9fac77312402be7df715c34.</p><p>Please refer to the code on at <a href="https://github.com/OpenDevICON/bandprotocol-dice">https://github.com/OpenDevICON/bandprotocol-dice</a></p><p>This is just a simple example to showcase how one can get a random number from BandProtocol and set it to a SCORE in ICON. This is not a production ready app and should just be used to understand the moving parts.</p><p>The front end is integrated with the iconex wallet and users can place a bet and submit transactions using the iconex wallet. When the submit button is pressed it calls the <a href="https://github.com/OpenDevICON/bandprotocol-dice/blob/master/dice_frontend/src/App.js"><em>callBet</em></a> function which in turn submits a transaction to the <a href="https://github.com/OpenDevICON/bandprotocol-dice/blob/master/dice_score/dice.py">Dice</a> score calling its <em>call_bet</em> method. This in turn calls the <em>get_random</em> function to get a random number from another score RandomNumber.</p><p>This <a href="https://github.com/OpenDevICON/bandprotocol-dice/blob/master/dice_score/random_number.py">RandomNumber</a> SCORE showcases the integration with BandProtocol.</p><p>This score has a <em>set_number</em> function which in turn calls a Bridge SCORE provided by the platform. Bridge score has a function <em>relay_and_verify(proof)</em> . This is the core of the Band Protocol mechanism that allows calling an oracle externally and still be able to pass and verify the result in the blockchain using <a href="https://docs.bandchain.org/whitepaper/lite-client-protocol.html">Light Client Protocol</a>. Please go through this Light Client Protocol to understand the details of proof mechanism that secures and validates the data obtained off chain from BandProtocol.</p><p>In our example , the backend <a href="https://github.com/OpenDevICON/bandprotocol-dice/blob/master/backend/index.js">script</a>, interacts with BandProtocol and calls the <a href="https://guanyu-devnet.cosmoscan.io/oracle-script/11">Quantum Random Number Generator </a>Oracle script. The result proof is sent to <a href="https://github.com/OpenDevICON/bandprotocol-dice/blob/master/dice_score/random_number.py">RandomNumber</a> score’s set_number. This function in turn calls the relay_and_verify(proof) on the Bridge to validate the proof and get the request and return parameters. Return parameter has the random number that this then set in the score used by the Dice SCORE.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a94dacfebf84" width="1" height="1" alt=""><hr><p><a href="https://medium.com/opendevicon/icon-bandprotocol-integration-a94dacfebf84">Icon-BandProtocol Integration</a> was originally published in <a href="https://medium.com/opendevicon">OpenDevICON</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to make use of token SCOREs in ODI library?]]></title>
            <link>https://medium.com/opendevicon/how-to-make-use-of-token-scores-in-odi-library-61e939e87cdc?source=rss-a809fbf2775c------2</link>
            <guid isPermaLink="false">https://medium.com/p/61e939e87cdc</guid>
            <category><![CDATA[cores]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[token-library]]></category>
            <category><![CDATA[icon-foundation]]></category>
            <dc:creator><![CDATA[OpenDevICON]]></dc:creator>
            <pubDate>Mon, 09 Nov 2020 17:08:22 GMT</pubDate>
            <atom:updated>2020-11-10T10:58:57.148Z</atom:updated>
            <content:encoded><![CDATA[<h3>OpenDevICON</h3><p><a href="https://opendevicon.io/">OpenDevICON</a> is an initiative to support ICON developers by making SCORE development easier, faster and convenient. OpenDevICON SCORE library helps you minimize risk by using battle-tested libraries for ICON blockchain. It includes the implementations of IRC Standards, IRC2, IRC3 and IRC16 with added functionalities than the default<a href="https://github.com/icon-project/IIPs"> IIP standard</a>. The libraries are open source, and available on<a href="https://github.com/OpenDevICON/odi-contracts"> github</a>. You can inherit the library and use it in your SCORE, or make changes to the SCORE library as per your requirements and use it.</p><p>The section below, shows how you can effectively use a IRC2 token SCORE library for your use case.</p><p>First, initialize a SCORE project using tbears cli command.</p><pre>tbears init testtoken TestToken</pre><p>Then, the project will be initialized. The file testtoken.py is the main SCORE file.</p><p>ICON doesn’t support import of external libraries other than iconservice in SCORE. So, we need to get the odi-contracts library inside the testtoken folder to implement it. For this, you can clone the IRC2 library github repo. Or, alternatively you can use the following command to get IRC2 library in the current directory.</p><pre>pip install odi-token-contracts -t .</pre><p>Now, the IRC2 token library is downloaded to your SCORE project. It consists of following extensions of basic IRC2 standard:</p><p>- IRC2Mintable</p><p>- IRC2Burnable</p><p>- IRC2Pausable.</p><p>- IRC2Capped</p><p>- IRC2Snapshot</p><p>- Access(Roles)</p><p>IRC2 is a standard implementation of IRC2 Standard. The mintable token extends IRC2 adding the mint method. Minting is the process of creating new tokens out of thin air, and only the owner of the token contract can mint new tokens. Capped token is the extension of the mintable token and introduces cap, which is a maximal amount of tokens that can be minted. Burnable token extends IRC2 adding the burn method. Using this, the minted tokens can be destroyed. Pausable token changes IRC2 token in the way that transferring tokens is impossible when the token is paused. Only the owner can pause and unpause the smart contract. You can learn more about these contracts<a href="https://docs.opendevicon.io/score-library/irc2standard"> here</a>.</p><p>Now, these contracts can be inherited in your main SCORE file, i.e. testtoken.py.</p><p>For example, if you need mintable, burnable, paused and capped feature in your SCORE, you can just import those contracts like:</p><pre>from .ODIContracts.tokens.IRC2 import IRC2Mintable</pre><pre>from .ODIContracts.tokens.IRC2 import IRC2Burnable</pre><pre>from .ODIContracts.tokens.IRC2 import IRC2Pausable</pre><p>Then, inherit these imported classes in the main class of your score by:</p><pre>class TestToken(IRC2Mintable, IRC2Burnable, IRC2Pausable):</pre><pre>pass</pre><p>Since, you are inheriting the don’t need the token SCOREs, which has __init__, on_install and on_update method, you don’t need to have those methods in your main SCORE file.</p><p>Now, all the features defined in IRC2, IRC2 Mintable, IRC2 Burnable and IRC2 Pausable can now be used in your SCORE.</p><p>On doing this, only the owner of the contract can mint, burn or pause the tokens. If you need others to be able to mint, burn or pause the tokens, then you can inherit roles in the same way and add addresses which will be allowed to mint, burn and pause the contracts respectively. Since the contracts will be in the SCORE project, you can modify the libraries if needed. The possibilities are endless.</p><p>IRC3 is a standard interface for non-fungible tokens on ICON network. The IRC3 library offers Pausable, Burnable, Mintable and Updatable features along with the default standards mentioned in<a href="https://github.com/icon-project/IIPs/blob/master/IIPS/iip-3.md"> IIP3 standard</a>. The implementation of IRC3 library is similar to IRC2 library. First, download the IRC3 library in your SCORE folder, then import the required contracts and inherit them in the main SCORE.</p><p>IRC16 token aims to simplify the process of creating blockchain-based securities and tokenized assets. It provides a suite of standard interfaces for issuing / redeeming security tokens, managing their ownership and transfer restrictions to the token holders. To implement it, first get the IRC16 library folder from github in your SCORE folder. Then, the process is same as IRC2 and IRC3 tokens. You just import the required contracts to your main SCORE file. IRC16 library offers Capped, Pausable and Controllable feature along with the standards defined in the IIP16 standard.</p><p>As you can see, the process of using the ODI token libraries are same. You first download the required library in your SCORE project, then inherit the required SCOREs and use them. You can add other methods in the SCORE as per the requirement in your project.</p><p>To deploy the contracts and interact with SCORE, you can follow the steps<a href="https://docs.opendevicon.io/jupyter-notebook/scoreinteraction"> here</a>. For detailed information on creating your own IRC2 token using this library, and deploying it on the testnet, and testing various methods provided by the ODI library, you can go<a href="https://docs.opendevicon.io/jupyter-notebook/create-your-own-token"> here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=61e939e87cdc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/opendevicon/how-to-make-use-of-token-scores-in-odi-library-61e939e87cdc">How to make use of token SCOREs in ODI library?</a> was originally published in <a href="https://medium.com/opendevicon">OpenDevICON</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is the snapshot token and how does the snapshotting of token balances at a specific point in…]]></title>
            <link>https://medium.com/opendevicon/what-is-the-snapshot-token-and-how-does-the-snapshotting-of-token-balances-at-a-specific-point-in-cac56c6e62cd?source=rss-a809fbf2775c------2</link>
            <guid isPermaLink="false">https://medium.com/p/cac56c6e62cd</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[snapshot]]></category>
            <category><![CDATA[icon-foundation]]></category>
            <dc:creator><![CDATA[OpenDevICON]]></dc:creator>
            <pubDate>Mon, 09 Nov 2020 17:03:04 GMT</pubDate>
            <atom:updated>2020-11-09T17:03:04.730Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is the snapshot token and how does the snapshotting of token balances at a specific point in time work?</h3><h3>What is snapshot?</h3><p>The term snapshot refers to the ability to record the state of something at a specific point in time. In blockchain, a snapshot refers to the act of recording the state of a blockchain, at a particular block height. In our case, it is used to record the total supply and balance of token holders at specific point in time.</p><h3>Double spending problem</h3><p>Double spending is a potential flaw in digital cash scheme in which the same digital token can be spent more than once. Since IRC2 tokens is basically a digital file it’s easier to duplicate than actual money. This means some people can manipulate their way to paying more than once with the same token. Here, the cryptocurrency is essentially stolen.</p><p>So, it’s obvious that we need to solve this issue. To avoid this, we implement snapshot mechanism in our IRC2 contract. The implementation can be found<a href="https://github.com/OpenDevICON/odi-contracts/blob/master/ODIContracts/tokens/IRC2/IRC2snapshot.py"> here</a>, in odi-contracts repo of OpenDevICON.</p><p>Snapshot is used to avoid the double spending problem. This system runs the risk that many copies of the same bitstring are spent at different merchants. In naive implementation, it is possible to perform a “double spend” attack by reusing the same balance from different accounts.</p><p>The snapshot contract extends an IRC2 token with a snapshot mechanism. When a snapshot is created, the balances and total supply at the time are recorded for later access.</p><p>Snapshot are created by the internal <strong><em>_snapshot</em></strong> function, which will emit a snapshot event and set a snapshot id in the blockchain. balanceOfAt external method is used to get the balance of a addresss at particular snapshot id. Similarly, totalSupplyAt method is used to get the total supply at a particular snapshot id.</p><p>Snapshots are needed during transfer operation, mint operation and burn operation. When transferred, the snapshot of sending and recieving account needs to be updated. Similarly, during mint operation, the snapshot of address where the token was minted and the total supply needs to be changed. During burn operation, the snapshot of address where the token was burned from and the total supply needs to be changed.</p><p><strong>Before diving deeper, let’s learn what these variables mean…</strong></p><p><strong>_current_snapshot_id</strong> : The current snapshot id. (VarDB)</p><p><strong>_account_balance_snapshot</strong>: It is used to keep track of snapshot_id, and the account balance at that id. <em>length</em> is used to connect between them. Length is like the index of an array in this case. It is equivalent to 2 level 1 dicts combined.</p><p>For reference:</p><pre>ids = {0:0, 1:10, 2: 30, 3:50}</pre><pre>vals = {0:100, 1:500, 2: 200, 3:1000}</pre><p>Here, 0,1,2,3 i.e. the keys in both dicts are same, and they represent length. The values in ids represent snapshot id at that particular length, and values in vals represent balance at that particular length.</p><p><strong>_total_supply_snapshot</strong>: It is used to keep track of total supply at a particular snapshot id. It works similar to account balance snapshot.</p><h3>How does updating account snapshot work?</h3><p>Here, first the current snapshot id is fetched and is set to current_id. Then, the balance of that account is set to current_value. The <em>length</em>, the key used to connect snapshot id with balance, is initialized to 1 when the contract is deployed. That value is set to length variable.</p><p>If length is 0, then, the snapshot balance of that account at length 0 is set to current_value, i.e. the balance of that account. Then, the length is increased. Generally, the length is not zero, and in this case, last_snapshot_id is set to the length-1.</p><p>Now, if the last_snapshot_id is less than current id, the snapshot id for that account at that length is set to current_id, value at that length is set to current_value and the length is updated by 1. Else, the value at length-1 is set to current_value.</p><h3>How does updating total supply snapshot work?</h3><p>This works similar to account snapshot update, except for balance of a particular address is replaced by total supply. Here, in DictDB, we don’t need additional depth for wallet address. The snapshot id is fetched, and length for total supply snapshot is fetched and set to local variables current_id and current_value respectively.</p><p>If length is 0, then, the snapshot total supply at length 0 is set to current_value, i.e. the total supply. Then, the length is increased. Generally, the length is not zero, and in this case, last_snapshot_id is set to the length -1.</p><p>Now, if the last_snapshot_id is less than current id, the snapshot id at that length is set to current_id, value at that length is set to current_value and the length is updated. Else, the value at length-1 is set to current_value.</p><p>Now, that updating account and total supply snapshot are covered, let’s see how we can get the balance of a account or total supply at a particular snapshot.</p><h3>balanceOfAt</h3><p>This method is used to find the balance of a particular account at a particular snapshot id. The snapshot id starts at 0 and is updated by 1. So, it cannot be less than 0.</p><p>When a valid snapshot id is queried, there are the following possibilties:</p><p>- The queried value was modified after the snapshot was taken.</p><p>- The value was not modified after the snapshot was taken.</p><p>- More snapshot ids were created after the requested one.</p><p>So, basically we need to find the balance at that id.</p><p>Here, we initialize low as 0 and high as the length.</p><p>While, the low value is less than high, we calculate mid by integer division of low and high. Then the id of that account when length = mid is fetched. If it is greater than snapshot id, high is set to mid. Else, low is set to mid + 1. This continues till the condition low is less than high is false.</p><p>Then, if the queried snapshot id is equal to the 0 length, then that value at 0 length is returned.</p><p>If low is equal to 0, 0 is returned, i.e. balance at that snapshot id is zero.</p><p>Else, the balance of that account at length `low-1` is returned.</p><p>This can be a bit complex to understand. It can be simplified by the following code snippet for understanding.</p><pre>low = 0</pre><pre>high = 3</pre><pre>_snapshot_id = 50</pre><pre>ids = {0:0, 1:10, 2: 30, 3:50}</pre><pre>vals = {0:100, 1:500, 2: 200, 3:1000}</pre><pre>while (low &lt; high):</pre><pre>mid = (low + high) // 2</pre><pre>if ids[mid] &gt; _snapshot_id:</pre><pre>high = mid</pre><pre>else:</pre><pre>low = mid + 1</pre><pre>if ids[0] == _snapshot_id:</pre><pre>print(vals[0])</pre><pre>elif low == 0:</pre><pre>print(0)</pre><pre>else:</pre><pre>print(vals[low])</pre><p>Here, the keys in the dictionaries, indicate length. The value in dict ids represent snapshot id, equivalent to</p><p><em>_account_balance_snapshot[_account][‘ids’][length]</em> in the code. The value in vals represent balance at that length, equivalent to</p><p><em>account_balance_snapshot[_account][‘values’][length]</em> in the code.</p><p>Note that, the initial length is set to 1 in on_install method. So, in the above snippet, we use vals[low] only, in the last line.</p><h3>totalSupplyAt</h3><p>This method is used to find the total supply at a particular snapshot id. The snapshot id cannot be less than 0.</p><p>This works exactly similar to the balanceOfAt method, except the total supply value is fetched instead of balance of particular account.</p><p>This is how snapshotting of token balances work at specific snapshot id.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cac56c6e62cd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/opendevicon/what-is-the-snapshot-token-and-how-does-the-snapshotting-of-token-balances-at-a-specific-point-in-cac56c6e62cd">What is the snapshot token and how does the snapshotting of token balances at a specific point in…</a> was originally published in <a href="https://medium.com/opendevicon">OpenDevICON</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>