<?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 Prajwol Gyawali on Medium]]></title>
        <description><![CDATA[Stories by Prajwol Gyawali on Medium]]></description>
        <link>https://medium.com/@prajwolgyawali?source=rss-a3bb40fb66a1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*cdgaB_qQZTCoR0lW</url>
            <title>Stories by Prajwol Gyawali on Medium</title>
            <link>https://medium.com/@prajwolgyawali?source=rss-a3bb40fb66a1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 22:17:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@prajwolgyawali/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[Getting started with arkworks-rs]]></title>
            <link>https://medium.com/@prajwolgyawali/getting-started-with-arkworks-rs-e5ceaca895a9?source=rss-a3bb40fb66a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/e5ceaca895a9</guid>
            <category><![CDATA[zero-knowledge-proofs]]></category>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[cryptography]]></category>
            <dc:creator><![CDATA[Prajwol Gyawali]]></dc:creator>
            <pubDate>Thu, 26 Oct 2023 09:12:42 GMT</pubDate>
            <atom:updated>2023-10-26T09:13:17.312Z</atom:updated>
            <content:encoded><![CDATA[<h4>Part I — Working with the Field</h4><blockquote>This article serves as a beginner’s guide and is tailored for readers who are already familiar with field arithmetic and possess a basic background in the Rust programming language.</blockquote><h3>Introduction</h3><p><a href="https://github.com/arkworks-rs/"><strong>arkworks</strong></a> is a robust Rust ecosystem designed for zkSNARK programming. The libraries within the arkworks ecosystem offer efficient implementations of all the essential components needed to create zkSNARK applications, ranging from generic finite fields to R1CS constraints for common functionalities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*AJ4bLdTdNaFIgAApnBSwiQ.png" /><figcaption>Arkworks Libraries. <a href="https://www.youtube.com/watch?v=_Zcz4Y4yt1Q&amp;t=477s">Source</a></figcaption></figure><p>In this article, our focus will be on ark-ff, which specializes in finite field arithmetic.</p><h3>Understanding BigInteger</h3><p>In the realm of finite fields, we often deal with unsigned integers that exceed the limits supported by the language. In Rust, unsigned integers upto u128 (128 bits) is supported. To accommodate fields of <strong>arbitrary sizes</strong>, we utilize BigInteger. In arkworks, BigInteger <a href="https://github.com/arkworks-rs/algebra/blob/master/ff/src/biginteger/mod.rs#L26C1-L28C1">is implemented</a> as an array of <strong>u64</strong> values.</p><pre>#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, Zeroize)]<br>pub struct BigInt&lt;const N: usize&gt;(pub [u64; N]);</pre><blockquote>BigInteger represents an integer of upto 64 bits as an array of size 1.<br>BigInteger represents an integer of upto 65–128 bits as an array of size 2.<br>BigInteger represents an integer of upto 128–191 bits as an array of size 3. <br>and so on….</blockquote><h3>Defining a Field</h3><p>Now that we understand BigInteger, let’s delve into how a Field is used with arkworks. Before we proceed, it’s important to note that ark-ff, the library for finite field arithmetic, needs to be installed to work with finite fields in your Rust project. You can install it using the following command:</p><p>&gt; cargo add ark-ff</p><p>Once ark-ff is installed, you can proceed to define a finite field.</p><p>To define a Field, we begin by creating a configuration struct for that field. This configuration requires two crucial elements: <strong>the modulus</strong> of the field and the <strong>generator of </strong>the field. Recall that a generator is a field element whose powers generates the entire field.</p><p>An example of a config is given below.</p><pre>use ark_ff::fields::{MontConfig};<br><br>#[derive(MontConfig)]<br>#[modulus = &quot;17&quot;]<br>#[generator = &quot;3&quot;]<br>pub struct FqConfig;</pre><p>MontConfig specifies constants and arithmetic procedures for <a href="https://en.wikipedia.org/wiki/Montgomery_modular_multiplication">Montgomery arithmetic</a> over the prime field with given modulus.</p><p>With the configuration in place, we can now define a type for elements of this finite field as follows:</p><pre>use ark_ff::fields::{Field, MontBackend, MontConfig};<br>use ark_ff::Fp;<br><br>#[derive(MontConfig)]<br>#[modulus = &quot;17&quot;]<br>#[generator = &quot;3&quot;]<br>pub struct FqConfig;<br>pub type Fq = Fp&lt;MontBackend&lt;FqConfig, 1&gt;, 1&gt;;</pre><blockquote>1. MontConfig is a trait and MontBackend implements the MontConfig Trait. <br>2. Since Rust is statically typed language, we need to explicitly mention the size of the field being used. Here our modulus can be represented by a single u64.</blockquote><p>For an example with a larger field, consider the base field of the BLS12_381 curve:</p><pre>use ark_ff::fields::{MontBackend, MontConfig};<br>use ark_ff::Fp;<br><br>#[derive(MontConfig)]<br>#[modulus = &quot;4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559787&quot;]<br>#[generator = &quot;2&quot;]<br>pub struct FqConfig;<br>pub type Fq = Fp&lt;MontBackend&lt;FqConfig, 6&gt;, 6&gt;;</pre><blockquote>Since the base field has 381 bits, we use u64 array of of size 6 that can accommodate for 384 bits.</blockquote><p>To simplify working with higher bits, arkworks has defined explicit types for these scenarios:</p><pre>pub type Fp64&lt;P&gt; = Fp&lt;P, 1&gt;;<br>pub type Fp128&lt;P&gt; = Fp&lt;P, 2&gt;;<br>pub type Fp192&lt;P&gt; = Fp&lt;P, 3&gt;;<br>...<br>pub type Fp832&lt;P&gt; = Fp&lt;P, 13&gt;;</pre><p>Consequently, our field can also be used with these types as shown below:</p><pre>use ark_ff::fields::{Field, Fp64, MontBackend, MontConfig};<br><br>#[derive(MontConfig)]<br>#[modulus = &quot;17&quot;]<br>#[generator = &quot;3&quot;]<br>pub struct FqConfig;<br>pub type Fq = Fp64&lt;MontBackend&lt;FqConfig, 1&gt;&gt;;</pre><blockquote>This approach is consistently employed across the <a href="https://github.com/arkworks-rs/curves">curves repository</a> of arkworks.</blockquote><h3>Performing Field Arithmetic</h3><pre>use ark_ff::fields::{Field, Fp64, MontBackend, MontConfig};<br><br>#[derive(MontConfig)]<br>#[modulus = &quot;17&quot;]<br>#[generator = &quot;3&quot;]<br>pub struct FqConfig;<br>pub type Fq = Fp64&lt;MontBackend&lt;FqConfig, 1&gt;&gt;;<br><br>fn main() {<br>    let a = Fq::from(9);<br>    let b = Fq::from(10);<br><br>    assert_eq!(a, Fq::from(26));          // 26 =  9 mod 17<br>    assert_eq!(a - b, Fq::from(16));      // -1 = 16 mod 17<br>    assert_eq!(a + b, Fq::from(2));       // 19 =  2 mod 17<br>    assert_eq!(a * b, Fq::from(5));       // 90 =  5 mod 17<br>    assert_eq!(a.square(), Fq::from(13)); // 81 = 13 mod 17<br>    assert_eq!(b.double(), Fq::from(3));  // 20 =  3 mod 17<br>    assert_eq!(a / b, a * b.inverse().unwrap()); // need to unwrap since `b` could be 0 which is not invertible<br>    assert_eq!(a.pow(b.into_bigint()), Fq::from(13)); // pow takes BigInt as input<br>}</pre><p>To get a list of all supported actions on Field, look into the <a href="https://github.com/arkworks-rs/algebra/blob/master/ff/src/fields/mod.rs#L161">Field trait</a>.</p><h4>Working with Predefined Fields</h4><p>arkworks has thoughtfully implemented the commonly used elliptic curves and their respective base fields. You can find a list of all the implemented curves <a href="https://github.com/arkworks-rs/curves">here</a>. To use any of these curves, simply add them to your project using the following command:</p><p>&gt; cargo add ark-{CURVE_NAME}</p><p>For instance, to include the secp256k1 curve, execute:</p><p>&gt; cargo add ark-secp256k1</p><p>Once the curve is added, you can seamlessly utilize its base field and order as finite fields in your code:</p><pre>use ark_secp256k1::Fq as Fq;<br>fn main() {<br>    let a = Fq::from(99);<br>    let b = Fq::from(10);<br>}</pre><h4>Working With Randomness</h4><p>When dealing with larger fields, you may need to generate random elements from the field, which can be done as follows:</p><pre>use ark_std::{UniformRand};<br>use rand::{thread_rng};<br>use ark_test_curves::bls12_381::Fq as Fq;<br>fn main() {<br>    let mut rng = thread_rng();<br>    let a: Fq = Fq::rand(&amp;mut rng);<br>    let b: Fq = Fq::rand(&amp;mut rng);<br>}</pre><blockquote>Be sure to add both rand and ark-std crates to your project before importing them. Add them with the following commands:<br><em>&gt; cargo add ark-std<br>&gt; cargo add rand</em></blockquote><h4>Hashing To Field</h4><p>Sometimes it might be useful to get the output of the hash value as a field element. arkworks allows us to do that with HashToField which implements hash_to_field method that hashes the arbitrary messages to vector of finite field.</p><p>To leverage hashing within arkworks, you’ll first need to add a suitable hashing function to your project. For this example, we’ll use the <a href="https://crates.io/crates/sha2">SHA2 hash function</a>. You can add it to your project using the following command:</p><p>&gt; cargo add sha2</p><p>Next, import the necessary components:</p><pre>use ark_ff::field_hashers::{DefaultFieldHasher, HashToField};<br>use sha2::Sha256;</pre><p>Now, let’s create a hasher:</p><pre>let hasher = &lt;DefaultFieldHasher&lt;Sha256&gt; as HashToField&lt;Fq&gt;&gt;::new(&amp;[]);</pre><p>The new method takes a vector of <strong>bytes</strong> as input, which gets concatenated with the message during hashing. This helps separate potentially interfering instantiations of the hasher. For now we’ll just pass reference to empty array.</p><blockquote>Note: bytes are represented as u8</blockquote><p>To generate a hash, use the hash_to_field method, providing it with two inputs:<br>a. <strong>message</strong>: An array of bytes. <br>b. <strong>count</strong>: The number of desired outputs.</p><p>If you wish to hash a field element, you can achieve this by converting the field element into a BigInt and subsequently transforming the BigInt into an array of bytes. It&#39;s important to note that there are two methods of representing this array: <a href="https://en.wikipedia.org/wiki/Endianness">big-endian and little-endian</a>.</p><pre>use ark_std::{UniformRand};<br>use rand::{thread_rng};<br>use ark_secp256k1::Fq;<br>use ark_ff::field_hashers::{DefaultFieldHasher, HashToField};<br>use ark_ff::{BigInteger, PrimeField};<br>use sha2::Sha256;<br><br>fn main() {<br>    let mut rng = thread_rng();<br>    let a: Fq = Fq::rand(&amp;mut rng);<br>    <br>    let hasher = &lt;DefaultFieldHasher&lt;Sha256&gt; as HashToField&lt;Fq&gt;&gt;::new(&amp;[]);<br>    let preimage = a.into_bigint().to_bytes_be(); // Converting to big-endian<br>    let hashes: Vec&lt;Fq&gt; = hasher.hash_to_field(&amp;preimage, 2); // Returned vector is of size 2<br><br>}</pre><h3>Conclusion</h3><p>In conclusion, this introductory article has offered a glimpse world of finite field implementation within the arkworks-rs ecosystem. I’ve tried to cover essential concepts, from understanding the role of BigInteger in handling arbitrary field sizes to defining finite fields and performing arithmetic operations. To delve deeper into these concepts and explore practical implementations, we encourage you to refer to the actual code in the arkworks GitHub repository.</p><h3>References:</h3><ol><li><strong>arkworks</strong> GitHub repository: <a href="https://github.com/arkworks-rs">https://github.com/arkworks-rs</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e5ceaca895a9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Started With ICON]]></title>
            <link>https://medium.com/iconosphere-io/getting-started-with-icon-1efc56c218e9?source=rss-a3bb40fb66a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/1efc56c218e9</guid>
            <category><![CDATA[dapps]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[icon-foundation]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Prajwol Gyawali]]></dc:creator>
            <pubDate>Wed, 10 Jun 2020 12:36:10 GMT</pubDate>
            <atom:updated>2020-06-13T04:10:18.716Z</atom:updated>
            <content:encoded><![CDATA[<h4>Everything you need before deploying your first SCORE.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*nTvVY_IFHjIZzsTxjpDxMg.jpeg" /><figcaption>ICON Network Topology and Ecosystem | Source: <a href="https://medium.com/u/39cf298c">2infiniti</a></figcaption></figure><p>This article aims to introduce to the world of ICON SCORE development and is aimed for anyone who wants to understand about structure of SCORE and deploying your first SCORE. Sufficient links has been provided if the audience wants to explore the particular topic in detail.</p><h3><strong>Introduction</strong></h3><p>ICON Network is a general purpose blockchain protocol based on the native cryptocurrency ICX that can run smart contracts, adopt the <a href="https://medium.com/eosio/dpos-bft-pipelined-byzantine-fault-tolerance-8a0634a270ba">BFT-DPoS </a>(Delegated Proof-of-Stake) consensus protocol, and use an economic-governance protocol called <a href="https://wmckenzie.com/icons-delegated-proof-of-contribution-model/">DPoC </a>(Delegated Proof-of-Contribution). In the long term, ICON Network aims to be an interchain that <strong>connects multiple blockchains</strong> based on <a href="https://medium.com/helloiconworld/blockchain-transmission-protocol-btp-explained-c4d9927ad398">BTP technology</a>.</p><h3><strong>SCORE</strong></h3><p>SCORE (Smart Contract on Reliable Environment) is a smart contract running on ICON network. There are two unique aspects of ICON SCORE:</p><ol><li>The programming language is Python.</li></ol><blockquote>So, if you are familiar with Python, you can write SCORE code right away</blockquote><p>2. The deployed SCORE is upgradable. So, you can change the SCORE and the corresponding SCORE address still remains the same even after the upgrade.</p><h4><strong>Prerequisite</strong></h4><p>Before you start writing a SCORE, you need to <a href="https://www.icondev.io/docs/tbears-installation">install the <strong>T-Bears</strong></a>. T-Bears provides the following:</p><ul><li>Essential libraries for SCORE development, <a href="https://iconservice.readthedocs.io/en/latest/"><strong>iconservice</strong></a></li><li>Local emulated node environment, <strong>T-Bears Server</strong></li><li>CLI commands for deploying a SCORE and invoking the SCORE functions, <strong>T-Bears CLI</strong></li><li>SCORE <strong>test framework</strong></li></ul><h4>Creating a Workspace</h4><p>SCORE is written in Python programming language, so you can use any Python programming tools, as long as the required files, as listed below, are included in the SCORE project. These files are all plain text.</p><ul><li><strong>__init__.py:</strong> makes Python treat the directory containing the file as a package.</li><li><strong>project.py:</strong> The main module file of the SCORE to be executed at the top level. This file name should be given in the package.json.</li><li><strong>package.json:</strong> This file contains the basic information about the SCORE.</li></ul><p>Using T-Bears, you can create a workspace for writing SCORE. T-Bears creates the above-mentioned template files for SCORE and other configuration files for the development environments.</p><p>T-Bears init command will create a SCORE project.</p><pre>$ tbears init [project_name] [main_class_name]<br>$ tbears init sample_crowdsale SampleCrowdsale</pre><p><strong>Note:</strong> We will use sample_crowdsale as an example to understand the structure of score.</p><h3>Structure of SCORE</h3><p>SCORE is a collection of codes written in Python. There should be a main class which has member variables and methods. The main class name should be specified in the package.json as the value of main_score field so that ICON nodes determine which class should be loaded and executed as an entry point.</p><p>Every main class of SCORE should be inherited from <a href="https://iconservice.readthedocs.io/en/latest/classes.iconscorebase.html">IconScoreBase </a>and must implement three methods (__init__, on_install, on_update) that are invoked on loading, installing, and updating SCORE respectively.. If the main class is not derived from <a href="https://iconservice.readthedocs.io/en/latest/classes.iconscorebase.html">IconScoreBase</a>, it cannot be deployed. Moreover, the main class should have more than one external methods which are supposed to be invoked by transactions from EOA or other Smart Contracts.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3b6192ba44bc6ffb8dfd06449d16eaae/href">https://medium.com/media/3b6192ba44bc6ffb8dfd06449d16eaae/href</a></iframe><h4><a href="https://www.icondev.io/docs/writing-score#type-hints">Type Hints</a></h4><p>If you have never encountered upon code with : in the function argument and -&gt; at the end of function declaration, chances are you are unaware of <a href="https://docs.python.org/3/library/typing.html">type hinting</a> introduced in Python version 3.5. <br>def func (arg1: int, arg2: str) -&gt; int is an example of type hinting and it is highly recommended for the input parameters and return value in SCORE. Possible data types for method parameters are <strong>int</strong>, <strong>str</strong>, <strong>bytes</strong>, <strong>bool </strong>and Address. Although <strong>list</strong> and <strong>dict </strong>type are not supported for method parameters, they can be used as return types.</p><h4><a href="https://www.icondev.io/docs/writing-score#storing-state-data">Variables, Types and Data Structures</a></h4><p>A SCORE has different ways of storing data. The most important data should be stored in the <a href="https://iconservice.readthedocs.io/en/latest/classes.db.html">StateDB </a>(State Database), the state database in the blockchain. Since, the variables which reside in memory are volatile and will be reset when the nodes are restarted, SCORE developers need to use the wrapping classes of the state database, VarDB, ArrayDB, and DictDB, to store the state permanently.</p><ul><li><a href="https://iconservice.readthedocs.io/en/latest/classes.vardb.html"><strong>VarDB</strong></a><strong>(key, target db, return type) </strong>can be used to perform <strong>set </strong>method to assign a unique value to a variable and <strong>get</strong> method to return<strong> </strong>it.</li><li><a href="https://iconservice.readthedocs.io/en/latest/classes.arraydb.html"><strong>ArrayDB</strong></a><strong>(key, target db, return type)</strong> can be used to declare one dimensional array and to perform <strong>put</strong>, <strong>get </strong>and <strong>pop </strong>methods on it.</li><li><a href="https://iconservice.readthedocs.io/en/latest/classes.dictdb.html"><strong>DictDB</strong></a><strong>(key, target db, return type, dict depth (default is 1)) </strong>can be used to store unsorted objects and behaves more like Python dict.</li></ul><pre>varDB = VarDB(...)<br>varDB.set(100)       # right<br>varDB = 100          # wrong</pre><pre>arrayDB = ArrayDB(...)<br>arrayDB[0] = 100     # right<br>arrayDB = 100        # wrong</pre><pre>dictDB = DictDB(...)<br>dictDB[&#39;key0&#39;] = 100 # right<br>dictDB = 100         # wrong</pre><h4><a href="https://www.icondev.io/docs/writing-score#implementing-score-external-methods">Python decorators</a></h4><p>Decorators makes our code shorter and more Pythonic. ICON provides us with following decorators:</p><ul><li><strong>External decorators:</strong> Methods decorated with @external can be called from outside the contract. If a method is decorated with a readonly parameter, i.e., @external(readonly=True), the method will have read-only access to the state database.</li><li><strong>Payable decorators:</strong> Only the methods with @payable decorator are permitted to receive incoming ICX coins.</li><li><strong>Eventlog decorator: </strong>Methods decorated with @eventlog can be called within SCORE codes during the execution of a transaction to include custom event logs in its TxResult as eventlogs.</li></ul><h4><a href="https://www.icondev.io/docs/writing-score#built-in-properties">Built-in Properties</a></h4><p>These are member variables supported by IconScoreBase, whose values are set by the ICON platform to deliver necessary information to the SCORE. Therefore, they are read-only variables and do not allow to be modified by the contract.</p><ul><li><strong>msg</strong>: Holds information of the account who called the SCORE method. msg.sender hold the address of method who called the method and msg.value is the amount of ICX that sender attempts to transfer.</li><li><strong>tx:</strong> Holds transaction information. tx.origin holds the account who created transaction, tx.origin holds transactoin index, tx.hash holds transaction hash.</li><li><a href="https://iconservice.readthedocs.io/en/latest/classes.icx.html"><strong>icx</strong></a><strong>:</strong> Holds object used to transfer ICX coins. See <a href="https://www.icondev.io/docs/writing-score#section-transferring-icx">Transferring ICX</a> for details.</li><li><strong>db:</strong> An instance used to access the state <a href="https://iconservice.readthedocs.io/en/latest/classes.db.html">ScoreDB</a>.</li></ul><h4><a href="https://www.icondev.io/docs/writing-score#invoking-other-score-methods">InterfaceScore</a></h4><p>InterfaceScore is an interface class that is used to invoke other SCORE’s method.</p><h4><a href="https://www.icondev.io/docs/writing-score#exception-handling">Exception Handling</a> and <a href="https://www.icondev.io/docs/writing-score#fallback">fallback</a></h4><p>You can handle exceptions in your contract,using therevert function. Although IconScoreException can also be used, it is not recommended. fallback is a special method that is executed whenever the smart contract receives plain ICX coins without data.</p><pre>@payable def fallback(self):    <br>    if something_wrong:<br>         revert(&#39;something wrong&#39;)</pre><h3>Sample Crowdsale</h3><p>We started by creating a workspace from scratch using tbears, moved to looking at the code generated by tbears and understanding the structure of SCORE. At this point we must be able to understand the basic syntax and layout of SCORE. Below is an implementation of Crowdsale that utilizes everything we have learned so far and meets the <a href="https://github.com/icon-project/IIPs/blob/master/IIPS/iip-2.md">IRC-2 standard</a>. It implements the following logic:</p><ul><li>Ability to set Crowdsale target, token contract address, and its duration when the contract is first deployed.</li><li>total_joiner_count function to return the number of contributors, and check_goal_reached function to test if the crowdsale target has been met.</li><li>safe_withdrawal function to transfer the fund to the beneficiary, if the sales target has been met. Otherwise, each contributor can withdraw their contributions back.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1YpOz3CHftEv3xAT7n1NWg.jpeg" /><figcaption>Flowchart of Sample Crowdsale | Source: <a href="https://medium.com/u/39cf298c">2infiniti</a></figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/338bb831a9fdfbcabff87ef538c28785/href">https://medium.com/media/338bb831a9fdfbcabff87ef538c28785/href</a></iframe><h3>Deploying Your Score</h3><p>ICON provides a couple of test environments, where you can deploy and test your SCORE without <em>real </em>ICX - namely <a href="https://www.icondev.io/docs/testnet#testnet-for-dapps"><strong>Yeouido </strong></a>(testnet for dApps), <a href="https://www.icondev.io/docs/testnet#testnet-for-exchanges"><strong>Euljiro </strong></a>(testnet for exchange developers) and <a href="https://www.icondev.io/docs/testnet#testnet-for-p-reps"><strong>Pagoda </strong></a>(testnet for <a href="https://www.icondev.io/docs/governance-p-rep">P-Reps</a>) before deploying it in the <a href="https://www.icondev.io/docs/mainnet"><strong>Mainnet</strong></a>. It should be noted that deploying a contract requires ICX. However, for test environments, you can use <a href="https://icon-faucet.ibriz.ai/">click here</a> to get some test ICX.</p><p>Moreover, you can also deploy your SCORE in the local emulated environment. You can either use <a href="https://www.icondev.io/docs/how-to-use-t-bears"><strong>tbears CLI commands</strong></a><strong> </strong>or<strong> </strong><a href="https://www.icondev.io/docs/sdk-overview"><strong>SDKs </strong></a>to deploy and interact with the SCORE locally before migrating it to the testnet or the mainnet. We will be using the <a href="https://github.com/icon-project/icon-sdk-python"><strong>Python SDK</strong></a>. Alternatively, you can use <a href="https://github.com/icon-project/icon-sdk-java"><strong>Java SDK</strong></a><strong>, </strong><a href="https://github.com/icon-project/icon-sdk-js"><strong>Javascript SDK</strong></a><strong> </strong>or <a href="https://github.com/icon-project/ICONKit"><strong>Swift SDK</strong></a><strong> .</strong></p><p>Python SDK can make use of <a href="https://jupyter.org/">Jupyter notebook</a> to obtain the same functionalities as using t-bears CLI commands, to interact with local blockchain as well as testnet and mainnet. Jupyter notebook provides the platform to write scripts in Python on the independent cells and execute them individually allowing easier debugging and code-reusability.</p><h4><strong>1. Import necessary packages</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ba2673af267281001f0bf61f84eebd2/href">https://medium.com/media/2ba2673af267281001f0bf61f84eebd2/href</a></iframe><h4>2.<strong> Select your environment</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/51639cc5e001149db93f3b80e086167d/href">https://medium.com/media/51639cc5e001149db93f3b80e086167d/href</a></iframe><h4>3.<strong> Create, store and import your wallet</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0fda94ccfaf3891b44429d63f3393fd4/href">https://medium.com/media/0fda94ccfaf3891b44429d63f3393fd4/href</a></iframe><h4>4. Set required parameters and send the signed DeployTransaction</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/adfd234f566e26c29609966fd4481d89/href">https://medium.com/media/adfd234f566e26c29609966fd4481d89/href</a></iframe><h4>5. Check the transaction result for any errors and save the SCORE Address</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/51915330e704c73982b6e75547a97c8a/href">https://medium.com/media/51915330e704c73982b6e75547a97c8a/href</a></iframe><h4>6. Interact with the SCORE</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1656d6d6c5687420b41f04e4a2d27362/href">https://medium.com/media/1656d6d6c5687420b41f04e4a2d27362/href</a></iframe><h4>7. Interact with the blockchain</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8dfd9a2bcc3074bc252d285af28084ca/href">https://medium.com/media/8dfd9a2bcc3074bc252d285af28084ca/href</a></iframe><h3>What’s next?</h3><ol><li><a href="https://www.icondev.io/">icondev.io</a> has everything you need to learn and explore each topic in detail.</li><li><a href="https://medium.com/u/39cf298c">2infiniti</a> has an excellent series of nice, step-by-step dApp development tutorials in ICON.</li><li><a href="https://www.devblockchain.tech/">devblockchain.tech</a> provides you a platfrom to learn SCORE programming in a simple and interactive way.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1efc56c218e9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/iconosphere-io/getting-started-with-icon-1efc56c218e9">Getting Started With ICON</a> was originally published in <a href="https://medium.com/iconosphere-io">ICONOsphere</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How is the Price of Bitcoin Determined?]]></title>
            <link>https://medium.com/thecapital/how-is-the-price-of-bitcoin-determined-2789d7f2b166?source=rss-a3bb40fb66a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/2789d7f2b166</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[finance]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[economics]]></category>
            <category><![CDATA[bitcoin]]></category>
            <dc:creator><![CDATA[Prajwol Gyawali]]></dc:creator>
            <pubDate>Sat, 23 May 2020 18:27:22 GMT</pubDate>
            <atom:updated>2021-05-04T11:10:15.968Z</atom:updated>
            <content:encoded><![CDATA[<h4>Modeling price of Bitcoin with supply and demand</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gsRqvL9z7FPJFxVc" /><figcaption>Photo by <a href="https://unsplash.com/@wildbook?utm_source=medium&amp;utm_medium=referral">Dmitry Demidko</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Laszlo Hanyecz, a Florida-based programmer &amp; crypto-enthusiast made what is considered to be the first purchase using Bitcoin (BTC). On May 22, 2010, he bought two pizzas for 10,000 BTC (valued at around 30 USD at that time); making this week a celebration of <strong>Bitcoin Pizza Day’s</strong> ten-year anniversary. At the price of Bitcoin today, those two pizzas cost him 92,056,200 USD.</p><h3>Bitcoin Meme Hub 🔞 on Twitter</h3><p>WOW 🤯 @PapaJohns put up a billboard Ad to celebrate todays #BitcoinPizzaDay 👏🍕</p><p>Despite the fact that Laszlo bought what are now the most expensive pizzas ever sold — he doesn’t regret it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I6iESdbvglr3gd8mZPWBfA.png" /><figcaption>Full Thread at: <a href="https://bitcointalk.org/index.php?topic=137.0">https://bitcointalk.org/index.php?topic=137.0</a></figcaption></figure><blockquote>“I’d like to think that what I did helped. But I think if it wasn’t me, somebody else would have come along. And maybe it wouldn’t have been pizza,” Hanyecz explained in May 2018.</blockquote><p>In fact, earlier in February 2018, he bought two pizzas using Bitcoin again. This time he only paid 0.00649 BTC (valued at around 68 USD at that time). In 10 years, 10,000 BTC went from being worth 30 USD to over 92 million USD. This naturally begs the question: How is the price of Bitcoin determined?</p><blockquote>The answer lies in the understanding of how the price of that pizza was determined in the first place.</blockquote><p>Let us consider that you are a pizza seller. You decide to set an initial price to 60 USD per pizza. You go to the market and set up a stall. But no one wants to buy your pizza; certainly, they don’t want to buy it for 60 USD because they value 60USD more than the pizza, or others are offering pizza at a lower price. As a result, there is no transaction. Naturally, you realize you have to drop the price to sell it. Now when you try to sell it for 30 USD, people are willing to buy because they value the pizza more than 30 USD. Thus, you have a transaction.</p><p>This is called the <strong>law of demand</strong>. When the price goes up, people buy less; when the price goes down, people buy more. This can be shown by the demand curve.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tb0Mw5zhfr1NMx1DR5Jyew.png" /></figure><p>On the other hand, if the price of pizza goes up, you have the incentive to produce more pizza. But if the price goes down, you don’t want to produce more pizzas. This is called the <strong>law of supply</strong> and shown by the supply curve.</p><h3>Surplus and Shortage</h3><p>If you think about the dynamics of the market, the price will fluctuate in order to bring supply into line with demand. If the supply is higher than demand, then there are pizzas going unsold. This mismatch is called <strong>surplus</strong>. Eventually, you would be willing to lower your price to sell those pizzas. And when the price comes down, that will cause the demand to actually go up.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NCVLTxBfX-78fMqdvA5wnQ.png" /></figure><p>Similarly, if demand is higher than supply, that means that there are people who want to get your pizza but can’t get them because there aren’t enough pizzas around. Again, there is a mismatch — this time called <strong>shortage</strong>. People will have to bid more, because of competition for that limited supply of your pizzas. So, if the demand is higher than the supply, the result is that price will go up. And when the price goes up, demand will come back down.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zjL_uUPKo7tyDGMBc9CLig.png" /></figure><p>In this way, market price fluctuates pulling supply and demand to converge to a point, an equilibrium point where <strong>supply meets demand</strong>. The price at this point is called the equilibrium price and this is exactly how the price of anything is determined — both Pizzas and Bitcoins.</p><h3>Supply and Demand in Bitcoin</h3><p>The supply of bitcoins is the supply of Bitcoins that are in circulation. Currently, of course, there’s a fixed number of Bitcoins in circulation. At the time of this writing, it’s about 18.5 million. And the rules of Bitcoin, as they currently stand, say that this number will slowly go up and hit a limit of 21 million eventually.</p><p>Let’s now look at demand. There are really two main sources of demand for bitcoins:<br>1. Demand for mediating fiat-currency transactions<br>2. Demand for investment</p><p>First, let’s look at mediating fiat-currency transactions. Imagine that <strong>A</strong>lice wants to buy something from <strong>B</strong>ob or wants to pay some money to Bob. And Alice and Bob want to transfer a certain number of dollars. But they find it convenient to use Bitcoin to do this transfer. Perhaps they’re at a distance, Alice wants to be able to email the money to Bob. Perhaps they like the fact that they can have very low (or no) transaction fees in Bitcoin; certainly, lower than some other service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t9dENP2xhxYB_C4drrfCeg.png" /><figcaption>Mediating Fiat Currency Transactions using Bitcoin</figcaption></figure><p>So, Alice buys Bitcoins for dollars. Alice then sends those Bitcoins to Bob as a Bitcoin transaction. Once that transaction is confirmed to Bob’s satisfaction, Bob will sell those Bitcoins for dollars and get the dollars back. So, Alice starts by putting in dollars, Bob ends by getting out dollars.</p><p>But the key thing to understand is that while mediating this transaction some Bitcoins have to be taken out of circulation and they’re devoted to serving this transaction. This creates a demand for those Bitcoins. If there are a lot of people who want to mediate transactions like this, that will generate demand for bitcoins. So, that’s the first source of demand.</p><p>The second source of demand is that bitcoin is sometimes demanded as an investment. That is somebody wants to buy bitcoins and hold them in the hope that the price of bitcoins will go up in the future and that they’ll be able to sell them. So, to the extent that people are buying and holding those bitcoins, those bitcoins are out of circulation.</p><h3>Model To Predict the Price of Bitcoin</h3><p>Now we can try building a simple model to predict the price of Bitcoin based on the effect of transaction mediation demand. Let us assume:</p><ul><li><strong>T</strong> is the total transaction value that’s going to be mediated via Bitcoins by everyone who’s participating in the market. And that’s going to be measured in dollars per second.</li><li><strong>D</strong> is the duration of time that Bitcoins need to be held out of circulations in order to mediate a transaction. That’s the time from when the payer buys the bitcoins to when the receiver is able to sell them back into the market, and we’ll measure that in seconds.</li><li><strong>S</strong> is the supply of Bitcoins that are available for this purchase.</li><li><strong>P </strong>is the price of Bitcoin per dollar measured in BTC/USD. Therefore, 1 USD = ( 1 / <strong>P</strong> ) BTC. <br> As of this writing <strong>P </strong>= 0.00011, i.e. 1 BTC= 9,198.83 USD.</li></ul><h4>Calculation</h4><p>Now we can do some calculations to determine the equilibrium price by equating demand and supply.</p><ul><li>Bitcoins needed to mediate transaction per second = Bitcoins available to mediate transactions per second</li><li>Total transaction Value (<strong>T</strong>) / Price (<strong>P</strong>) = Supply (<strong>S</strong>) / Duration needed for transaction (<strong>D</strong>)</li><li>Therefore, Price (<strong>P</strong>) = (<strong>T</strong> * <strong>D</strong> ) / <strong>S</strong></li></ul><p>Now if you think about it, D the duration does not change. Similarly, the total supply will max out at 21 million BTC, making it constant. Therefore, the price is going to be proportional to the demand for transaction mediation as measured in dollars. So, if demand for transaction mediation in dollars doubles, then the price of Bitcoins should double. In fact, we could graph the price of Bitcoin against some estimate of the demand for transaction mediation and see if they match up. And when we do this, they tend to match up pretty well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yBi5Po_sDcxaX-mRnD-ecA.png" /><figcaption>Bitcoin Price vs Transaction Amount to Active Addresses Ratio (TAAR). Source: <a href="https://coinmetrics.io/">coinmetrics.io</a></figcaption></figure><p>This is not a full model of the market by any means. In order to have a full model, we need to consider the activities of investors. We need to bear in mind that investors will demand bitcoins when they believe that the price will be higher in the future. So, we need to think about investors’ expectations, and investors’ expectations, of course, have something to do with what is the expected total transaction value demand in the future.</p><p>Ultimately, what determines the value of pizza is exactly what determines the price of Bitcoin; whether people demand it. Predicting the future price of Bitcoin is impossible. But we can sure ponder upon if the Bitcoin price would continue to rise steeply enough for users to remain willing to pay ever-higher transaction fees? Or will there eventually be a “death spiral” triggered by falling prices as users leave the system in mass, followed by miners giving up as collapsing transaction volumes force fees down to zero?</p><p><a href="https://twitter.com/thecapital_io">JavaScript is not available.</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Ff%2F3c1144%3Fas_embed%3Dtrue&amp;dntp=1&amp;display_name=Upscribe&amp;url=https%3A%2F%2Fupscri.be%2F3c1144&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/3b6b127891c5c8711ad105e61d6cc81f/href">https://medium.com/media/3b6b127891c5c8711ad105e61d6cc81f/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2789d7f2b166" width="1" height="1" alt=""><hr><p><a href="https://medium.com/thecapital/how-is-the-price-of-bitcoin-determined-2789d7f2b166">How is the Price of Bitcoin Determined?</a> was originally published in <a href="https://medium.com/thecapital">The Capital</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>