<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Bolum</title>
    <description>The latest articles on DEV Community by Bolum (@bolum).</description>
    <link>https://dev.to/bolum</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F27274%2Fb57c3d3b-8293-40e1-8847-c2fe767aa548.jpg</url>
      <title>DEV Community: Bolum</title>
      <link>https://dev.to/bolum</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bolum"/>
    <language>en</language>
    <item>
      <title>Bitcoin with C-Sharp</title>
      <dc:creator>Bolum</dc:creator>
      <pubDate>Fri, 26 Jun 2020 14:22:06 +0000</pubDate>
      <link>https://dev.to/bolum/bitcoin-with-c-sharp-afo</link>
      <guid>https://dev.to/bolum/bitcoin-with-c-sharp-afo</guid>
      <description>&lt;p&gt;In this tutorial, we are going to introduce Bitcoin using C. We will be using C#’s bitcoin library, called NBitcoin.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Install Nbitcoin&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dotnet add package NBitcoin
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Generate a private key&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;private key&lt;/strong&gt; in the context of Bitcoin is a secret number that allows bitcoins to be spent. Every Bitcoin wallet contains one or more &lt;strong&gt;private keys.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is how you generate a private key with NBitcoin:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var privateKey = new Key();

var bitcoinPrivateKey = privateKey.GetWif(Network.Main).ToString();

Console.WriteLine(bitcoinPrivateKey);

//L3X8YdfNAgPGhcQs1tbiAiyqG3Z5BJ4nYzfJPmxA7BJRGMi3AMPp
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Generate a public key&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var privateKey = new Key();

var bitcoinPrivateKey = privateKey.GetWif(Network.Main);

var bitcoinPublicKey = bitcoinPrivateKey.PubKey.ToString();

Console.WriteLine(bitcoinPublicKey);

//027f34ed880f6ee198b5b583472d7dcd640326a6f3d8530c6105cb3bf20b1b629e
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Create a Bitcoin address&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You know that your &lt;strong&gt;Bitcoin Address&lt;/strong&gt; is what you share to the world to get paid.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var privateKey = new Key();

var bitcoinPrivateKey = privateKey.GetWif(Network.Main);

var bitcoinPublicKey = bitcoinPrivateKey.PubKey;

var address = bitcoinPublicKey.GetAddress(ScriptPubKeyType.Segwit, Network.Main);

Console.WriteLine(address);


//bc1q7sq2samnm4nkpsylusuqw95t3ma8z5ayn7s5zk
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Generate Address from a known private key&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var key = "L1TmYw2edTAyF9CtSF64k2Qc3AkKa8t9xn1vMa92xCe9VCzTbYzV";

var bitcoinSecret = new BitcoinSecret(key);

var address = bitcoinSecret.PubKey.GetAddress(ScriptPubKeyType.Segwit,Network.Main);

Console.WriteLine(address);

//bc1qlq037jz8u9mlkwh3ccmky92yxflrqrmaz5dtyr
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Generate Mnemonic&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;mnemonic&lt;/strong&gt; recovery phrase or &lt;strong&gt;bitcoin&lt;/strong&gt; seed is a list of words which store all the information needed to recover a &lt;strong&gt;bitcoin&lt;/strong&gt; wallet&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var mnemo = new Mnemonic(Wordlist.English, WordCount.Twelve);

//key victory fashion rough torch ice lesson main grape actual horn dinosaur
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Generate Address from Mnemonic&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var mnemo = new Mnemonic("dry brown drive parade drastic shine embrace hard report loan fold iron", Wordlist.English);

var hdroot = mnemo.DeriveExtKey();

var pKey = hdroot.Derive(new KeyPath("m/84'/0'/0'/0/0"));

var address = pKey.PrivateKey.PubKey.GetAddress(ScriptPubKeyType.Segwit, Network.Main));

Console.WriteLine(address);

//bc1qv7z69wxrew84vv43xrnfrckkzj4wzalf99e2cs
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Generate Multiple Addresses from Mnemonic&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Derivation path follows this convention:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;m / purpose' / coin_type' / account' / change / address_index
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;So you can increase address_index from 0 to get new addresses from same mnemonic.&lt;/p&gt;

&lt;p&gt;For more details: &lt;a href="https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki"&gt;https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki&lt;/a&gt;&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var mnemo = new Mnemonic("orange soup note oil token top slab elder mercy mad wool congress", Wordlist.English); 

var hdroot = mnemo.DeriveExtKey(); 

var pKey = hdroot.Derive(new KeyPath("m/84'/0'/0'/0/0")); 

var pKey2 = hdroot.Derive(new KeyPath("m/84'/0'/0'/0/1")); 

Console.WriteLine(pKey.PrivateKey.PubKey.GetAddress(ScriptPubKeyType.Segwit, Network.Main)); 

Console.WriteLine(pKey2.PrivateKey.PubKey.GetAddress(ScriptPubKeyType.Segwit, Network.Main));

//bc1q3sfs9z8zl5c4jw5hxujv9p5gf2hseha7vkfeav

//bc1qk3myyedlqyvjg69cfmatypaep9hqa6rzcx9dcu
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this tutorial, we introduced bitcoin with c#. We saw how to generate a private key, public key, bitcoin address, mnemonic and also generate address from a mnemonic recovery phrase.&lt;/p&gt;

&lt;p&gt;**Source : &lt;a href="https://programmingblockchain.gitbook.io/programmingblockchain/"&gt;**https://programmingblockchain.gitbook.io/programmingblockchain/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;coffee: bc1qr0mfxvc94j5732r450z3uw9jfujmm9syn2uy3q&lt;/p&gt;

&lt;h2&gt;
  
  
  Connect:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/in/veektorh/"&gt;*Linkedin&lt;/a&gt;*&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
