Skip to content

Commit

Permalink
deploy: d57c716
Browse files Browse the repository at this point in the history
  • Loading branch information
phklive committed Feb 26, 2024
1 parent e1fe1c8 commit 1d64c88
Show file tree
Hide file tree
Showing 4 changed files with 196 additions and 70 deletions.
131 changes: 97 additions & 34 deletions introduction/getting-started.html
Original file line number Diff line number Diff line change
Expand Up @@ -178,23 +178,32 @@ <h1 class="menu-title">Polygon Miden Documentation</h1>
<main>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" integrity="sha384-AfEj0r4/OFrOo5t7NnNe46zW/tFgW6x/bCJG8FqQCEo3+Aro6EYUG4+cU+KJWu/X" crossorigin="anonymous">
<h1 id="getting-started"><a class="header" href="#getting-started">Getting started</a></h1>
<p>This tutorial guides you through the process of connecting to a remote Miden node using the Miden client. The Miden node processes transactions and creates blocks for the Miden rollup. The Miden client provides a way to execute and prove transactions, facilitating the interaction with the Miden rollup. By the end of this tutorial, you will be able to configure the Miden client, connect to a Miden node, and perform basic operations like sending transactions, generating and consuming notes.</p>
<h2 id="prerequisites"><a class="header" href="#prerequisites">Prerequisites</a></h2>
<p>This tutorial will guide you through the process generating a new Miden account, requesting funds from a public faucet and interacting with the Miden rollup using the Miden client.</p>
<p>The Miden node processes transactions and creates blocks for the Miden rollup. The Miden client provides a way to execute and prove transactions, facilitating the interaction with the Miden rollup. By the end of this tutorial, you will be able to configure the Miden client, connect to a Miden node, and perform basic operations like sending transactions, generating and consuming notes.</p>
<h3 id="prerequisites"><a class="header" href="#prerequisites">Prerequisites</a></h3>
<p>Before starting, ensure you have the following:</p>
<ul>
<li><strong>Rust Installed:</strong> You must have the Rust programming language installed on your machine. If you haven't installed Rust, you can download it from <a href="https://www.rust-lang.org/learn/get-started">the Rust website</a>.</li>
<li><strong>Node IP Address:</strong> Obtain the IP address of the running Miden node. This information can be acquired by contacting one of the Miden engineers.</li>
<li><strong>Miden client Installation:</strong> You need to install the <a href="https://github.com/0xPolygonMiden/miden-client">Miden client</a> and configure it to point to the remote node.</li>
<li>
<p><strong>Rust Installed:</strong> You must have the Rust programming language installed on your machine. If you haven't installed Rust, you can download it from <a href="https://www.rust-lang.org/learn/get-started">the Rust website</a>.</p>
</li>
<li>
<p><strong>Node IP Address:</strong> Obtain the IP address of the running Miden node. This information can be acquired by contacting one of the Miden engineers.</p>
</li>
<li>
<p><strong>Miden client Installation:</strong> You need to install the <a href="https://github.com/0xPolygonMiden/miden-client">Miden client</a> and configure it to point to the remote node.</p>
</li>
</ul>
<h2 id="step-1-configuring-the-miden-client"><a class="header" href="#step-1-configuring-the-miden-client">Step 1: Configuring the Miden client</a></h2>
<h2 id="part-1-creating-a-miden-account--using-the-faucet"><a class="header" href="#part-1-creating-a-miden-account--using-the-faucet">Part 1: Creating a Miden account &amp; using the faucet</a></h2>
<p>In this first part of the tutorial we will teach you how to create a new Miden account locally and how to receive funds from the public Miden faucet website.</p>
<h3 id="configuring-the-miden-client"><a class="header" href="#configuring-the-miden-client">Configuring the Miden client</a></h3>
<ol>
<li>
<p><strong>Download the Miden client:</strong> First, download the Miden client from its repository. Use the following command:</p>
<pre><code class="language-shell">git clone https://github.com/0xPolygonMiden/miden-client
</code></pre>
</li>
<li>
<p><strong>Navigate &amp; Configure the client:</strong> Navigate to the client directory and modify the configuration file to point to the remote Miden node. You can find the configuration file at <code>./miden-client.toml</code>. In the <code>[RPC]</code> section replace the <code>endpoint = { host: }</code> field with the address provided by the Miden engineer.</p>
<p><strong>Navigate &amp; Configure the client:</strong> Navigate to the client directory and modify the configuration file to point to the remote Miden node. You can find the configuration file at <code>./miden-client.toml</code>. In the <code>[RPC]</code> section replace the <code>endpoint = { host: }</code> field with the address provided by the Miden team.</p>
<pre><code class="language-shell">cd miden-client
</code></pre>
<p>Configuration file example:</p>
Expand All @@ -214,64 +223,118 @@ <h2 id="step-1-configuring-the-miden-client"><a class="header" href="#step-1-con
</code></pre>
</li>
</ol>
<h2 id="step-2-setting-up-the-miden-client"><a class="header" href="#step-2-setting-up-the-miden-client">Step 2: Setting-up the Miden client</a></h2>
<h3 id="creating-a-new-miden-account"><a class="header" href="#creating-a-new-miden-account">Creating a new Miden account</a></h3>
<ol>
<li>
<p><strong>Creating new accounts:</strong> To be able to interact with the Miden node we will need to generate accounts. For this example we will be generating 3 accounts: <code>basic-immutable</code> account A, <code>basic-immutable</code> account B and a <code>fungible-faucet</code>. You can generate new accounts using the following commands:</p>
<p><strong>Creating a new account:</strong> To be able to interact with the Miden rollup you will need to generate an account. For this first part of the example we will generate one <code>basic-immutable</code> account using the following command:</p>
<pre><code class="language-shell">miden-client account new basic-immutable
miden-client account new basic-immutable
miden-client account new fungible-faucet [...]
</code></pre>
<p>Please refer to the documentation of the CLI</p>
</li>
<li>
<p><strong>Listing accounts:</strong> To view the newly created accounts we can run the following command:</p>
<p><strong>Listing accounts:</strong> To view the newly created account we can run the following command:</p>
<pre><code class="language-shell">miden-client account -l
</code></pre>
<p>We should now see 3 available accounts listed:</p>
<p>We should now see 1 available account listed:</p>
<ul>
<li><code>basic-immutable</code> account A</li>
<li><code>basic-immutable</code> account B</li>
<li><code>fungible-faucet</code> account</li>
<li><code>basic-immutable</code></li>
</ul>
</li>
</ol>
<h3 id="requesting-tokens-from-the-public-faucet"><a class="header" href="#requesting-tokens-from-the-public-faucet">Requesting tokens from the public faucet</a></h3>
<ol>
<li>
<p><strong>Navigating to the faucet website:</strong> To request funds from the faucet navigate to the following website: <a href="https://ethdenver.polygonmiden.io/">Miden faucet website</a></p>
</li>
<li>
<p><strong>Requesting funds from the faucet:</strong> Now that you have created your Miden account and navigated to the faucet website you should now be able to copy your <code>AccountId</code> that has been printed by the <code>miden-client account -l</code> command that you used in the previous steps. Paste this id into the field present on the faucet website and click <code>Send me tokens!</code>. After a few seconds your browser should download or prompt you to download a file called <code>note.mno</code> (mno = Miden Note), save this file on your computer, it will be needed for the next steps and contains the funds sent by the faucet destined to your address.</p>
</li>
</ol>
<h3 id="importing-the-note-into-the-miden-client"><a class="header" href="#importing-the-note-into-the-miden-client">Importing the note into the Miden client</a></h3>
<ol>
<li>
<p><strong>Syncing node state:</strong> The client needs to periodically query the node to receive updates about entities that might be important in order to run transactions. The way to do so is by running the <code>sync</code> command:</p>
<p><strong>Importing &amp; visualising notes:</strong> From your terminal we will use the Miden client to import and visualise the note that you have received using the following commands:</p>
<pre><code class="language-shell">miden-client input-notes -i &lt;path-to-note&gt;
</code></pre>
<p>Now that the note has been successfully imported you should be able to visualise it's information using the following command:</p>
<pre><code class="language-shell">miden-client input-notes -l
</code></pre>
<p>As you can see the listed note is lacking a <code>commit-height</code> this is due to the fact that you have received a note off-chain but have not synced your view of the rollup to check that the note is valid and exists at the rollup level. This is essential to prevent double-spend and make sure that you consume notes that have not yet been nullified. Hence before consuming the note we will need to update or view of the rollup and sync.</p>
</li>
<li>
<p><strong>Syncing the client:</strong> The client needs to periodically query the node to receive updates about entities that might be important in order to run transactions. The way to do so is by running the <code>sync</code> command:</p>
<pre><code class="language-shell">miden-client sync
</code></pre>
</li>
</ol>
<h2 id="step-3-minting-an-asset"><a class="header" href="#step-3-minting-an-asset">Step 3: Minting an asset</a></h2>
<p>Since we have now synced our local view of the blockchain and have account information, we are ready to execute and submit tranasctions. For a first test, we are going to mint a fungible asset for a regular account.</p>
<pre><code class="language-shell">miden-client tx new mint &lt;regular-account-id-A&gt; &lt;faucet-account-id&gt; 1000
<h3 id="consuming-the-note--receiving-the-funds"><a class="header" href="#consuming-the-note--receiving-the-funds">Consuming the note &amp; receiving the funds</a></h3>
<ol>
<li>
<p><strong>Consuming the note:</strong> Now that we have synced the client the input-note that we have imported from the faucet should have a <code>commit-height</code> confirming it's existence at the rollup level:</p>
<pre><code class="language-shell">miden-client input-notes -l
</code></pre>
<p>This will execute, prove and submit a transaction that mints assets to the node. The account that executes this transaction will be the faucet as was defined in the node's configuration file. In this case, it is minting <code>1000</code> fungible tokens to <code>&lt;regular-account-id-A&gt;</code>.</p>
<p>This will add a transaction and an output note (containing the minted asset) to the local store in order to track their lifecycles. You can display them by running <code>miden-client tx list</code> and <code>miden-client input-notes list</code> respectively. If you do so, you will notice that they do not show a <code>commit height</code> even though they were submitted to the operator. This is because our local view of the network has not yet been updated. After updating it with a <code>sync</code>, you should see the height at which the transaction and the note containing the asset were committed. This will allow us to prove transactions that make use of this note, as we can compute valid proofs that state that the note exists in the blockchain.</p>
<h2 id="step-4-consuming-the-note"><a class="header" href="#step-4-consuming-the-note">Step 4: Consuming the note</a></h2>
<p>After creating the note with the minted asset, the regular account can now consume it and add the tokens to its vault. You can do this the following way:</p>
<pre><code class="language-bash">miden-client tx new consume-notes &lt;regular-account-id-A&gt; &lt;input-note-id&gt;
<p>We can now consume the note and add the funds contained inside it's vault to our account using the following commands:</p>
<pre><code class="language-shell">miden-client tx new consume-notes &lt;Account-Id&gt; &lt;Note-Id&gt;
</code></pre>
<p>This will consume the input note, which you can get by listing them as explained in the previous step. You will now be able to see the asset in the account's vault by running:</p>
<pre><code class="language-bash">miden-client account show &lt;regular-account-id-A&gt; -v
<p>You should be able to find your account and note id by listing both <code>accounts</code> and <code>input-notes</code>:</p>
<pre><code class="language-shell">miden-client account -l
miden-client input-notes -l
</code></pre>
<h2 id="step-5-transferring-assets-between-accounts"><a class="header" href="#step-5-transferring-assets-between-accounts">Step 5: Transferring assets between accounts</a></h2>
<p>Some of the tokens we minted can now be transferred to our second regular account. To do so, you can run:</p>
<pre><code class="language-shell">miden-client sync # Make sure we have an updated view of the state
miden-client tx new p2id &lt;regular-account-id-A&gt; &lt;regular-account-id-B&gt; &lt;faucet-account-id&gt; 50 # Transfers 50 tokens to account ID B
</li>
<li>
<p><strong>Visualising account vault:</strong> After successfully running the previous commands your account should now contained the tokens sent from the faucet. You can visualise your accounts vault by running the following command:</p>
<pre><code class="language-shell">miden-client account show &lt;Account-Id&gt; -v
</code></pre>
<p>You should now see your accounts vault containing the funds sent by the faucet.</p>
<h4 id="congratulations-you-finished-the-first-part-of-the-tutorial-continue-to-learn-more-about-miden-and-understand-how-to-send-peer-to-peer-private-off-chain-transactions"><a class="header" href="#congratulations-you-finished-the-first-part-of-the-tutorial-continue-to-learn-more-about-miden-and-understand-how-to-send-peer-to-peer-private-off-chain-transactions">Congratulations! You finished the first part of the tutorial, continue to learn more about Miden and understand how to send Peer-to-Peer private off-chain transactions!</a></h4>
</li>
</ol>
<h2 id="part-2-peer-to-peer-private-off-chain-transactions"><a class="header" href="#part-2-peer-to-peer-private-off-chain-transactions">Part 2: Peer-to-Peer private off-chain transactions</a></h2>
<p>In this second part of the tutorial we will teach you how to make off-chain transactions and send funds to another account using the Miden client.</p>
<blockquote>
<p><strong>Note</strong>:
We consider that you have done the first part of the turorial and that the state of your local client has not been reset.</p>
</blockquote>
<h3 id="setting-up-the-miden-client"><a class="header" href="#setting-up-the-miden-client">Setting-up the Miden client</a></h3>
<ol>
<li>
<p><strong>Creating a second account:</strong> To be able to send funds from one account to another we will need to generate one more account. For this example we will be generating 1 additional account: we generated <code>basic-immutable</code> account A in the first part of the tutorial. Here we will be creating <code>basic-immutable</code> account B using the following command:</p>
<pre><code class="language-shell">miden-client account new basic-immutable
</code></pre>
<p>Please refer to the documentation of the CLI</p>
</li>
<li>
<p><strong>Listing accounts:</strong> To view the newly created accounts we can run the following command:</p>
<pre><code class="language-shell">miden-client account -l
</code></pre>
<p>We should now see 2 available accounts listed:</p>
<ul>
<li><code>basic-immutable</code> account A (created during the first part of this tutorial)</li>
<li><code>basic-immutable</code> account B</li>
</ul>
</li>
</ol>
<h3 id="transferring-assets-between-accounts"><a class="header" href="#transferring-assets-between-accounts">Transferring assets between accounts</a></h3>
<p>Now that we have two accounts we are ready to transfer some of the tokens we received from the faucet into account A. We will now transfer some to our second regular account B. To do so, you can run:</p>
<pre><code class="language-shell">miden-client tx new p2id &lt;regular-account-id-A&gt; &lt;regular-account-id-B&gt; &lt;faucet-account-id&gt; &lt;Amount&gt;
</code></pre>
<p>This will generate a Pay-to-ID (<code>P2ID</code>) note containing 50 assets, transferred from one regular account to the other. If we sync, we can now make use of the note and consume it for the receiving account:</p>
<blockquote>
<p><strong>Note</strong>
The faucet account id can be found on the faucet website under the title "Miden faucet".</p>
</blockquote>
<p>This will generate a Pay-to-ID (<code>P2ID</code>) note containing <code>&lt;amount&gt;</code> assets, transferred from one regular account to the other. If we sync, we can now make use of the note and consume it for the receiving account:</p>
<pre><code class="language-shell">miden-client sync # Make sure we have an updated view of the state
miden-client input-notes list # Now use the second note id
miden-client tx new consume-notes &lt;regular-account-ID-B&gt; &lt;input-note-id&gt; # Consume the note
</code></pre>
<p>That's it! You will now be able to see <code>950</code> fungible tokens in the first regular account, and <code>50</code> tokens in the remaining regular account:</p>
<p>That's it! You should now be able to see both accounts containing assets coming from the faucet and then transferred from <code>Account A</code> to <code>Account B</code>.</p>
<pre><code class="language-shell">miden-client account show &lt;regular-account-ID-B&gt; -v # Show account B's vault assets (50 fungible tokens)
miden-client account show &lt;regular-account-ID-A&gt; -v # Show account A's vault assets (950 fungible tokens)
</code></pre>
<h3 id="clearing-the-state"><a class="header" href="#clearing-the-state">Clearing the state</a></h3>
<p>All state is maintained in <code>store.sqlite3</code>, located in the directory defined in the <code>miden-client.toml</code> file. In case it needs to be cleared, the file can be deleted; it will later be created again when any command is executed.</p>
<h2 id="conclusion"><a class="header" href="#conclusion">Conclusion</a></h2>
<p>Congratulations! You have successfully configured and used the Miden client to interact with a Miden node. With these steps, you can perform basic Miden rollup operations like sending transactions, generating and consuming notes.</p>
<p>Congratulations! You have successfully configured and used the Miden client to interact with a Miden rollup and faucet. With these steps, you can perform basic Miden rollup operations like sending transactions, generating and consuming notes.</p>
<p>For more information on the Miden client, refer to the <a href="https://github.com/0xPolygonMiden/miden-client">Readme of the Miden Client</a></p>
<p>For more information on the Miden rollup, refer to the <a href="https://0xpolygonmiden.github.io/miden-base/introduction.html">Miden documentation</a>.</p>

Expand Down
Loading

0 comments on commit 1d64c88

Please sign in to comment.