Bitcoin Forum
October 21, 2018, 11:47:58 AM *
News: Make sure you are not using versions of Bitcoin Core other than 0.17.0 [Torrent], 0.16.3, 0.15.2, or 0.14.3. More info.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: C#, NBitcoin and XPubkey  (Read 1103 times)
galgitron
Member
**
Offline Offline

Activity: 63
Merit: 10



View Profile
November 09, 2015, 07:30:10 PM
 #1

I'm attempting to write an algorithm that generates public bitcoin addresses from a known xpubkey. The key I'm using for testing can be found at blockchain.info at

https://blockchain.info/xpub/xpub6CUGRUonZSQ4TWtTMmzXdrXDtypWKiKrhko4egpiMZbpiaQL2jkwSB1icqYh2cfDfVxdx4df189oLKnC5fSwqPfgyP3hooxujYzAu3fDVmz

I'm trying something like this to generate the address on the path 0,0,0, as below:

Code:
        var pubkey = new ExtPubKey(Encoding.ASCII.GetBytes("6CUGRUonZSQ4TWtTMmzXdrXDtypWKiKrhko4egpiMZbpiaQL2jkwSB1icqYh2cfDfVxdx4df189oLKnC5fSwqPfgyP3hooxujYzAu3fDVmz"));
        Console.Writeline(pubkey.Derive(0).Derive(0).Derive(0).PubKey.GetAddress(Network.Main));

I'm not fully understanding something because I get a 'Invalid point encoding 103' when trying to instantiate the ExtPubKey.  Does anyone have working sample code?
1540122478
Hero Member
*
Offline Offline

Posts: 1540122478

View Profile Personal Message (Offline)

Ignore
1540122478
Reply with quote  #2

1540122478
Report to moderator
1540122478
Hero Member
*
Offline Offline

Posts: 1540122478

View Profile Personal Message (Offline)

Ignore
1540122478
Reply with quote  #2

1540122478
Report to moderator
There are several different types of Bitcoin clients. EWallets such as Coinbase are like banks -- a central organization has complete control over your money. You shouldn't put much money in EWallets.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1540122478
Hero Member
*
Offline Offline

Posts: 1540122478

View Profile Personal Message (Offline)

Ignore
1540122478
Reply with quote  #2

1540122478
Report to moderator
1540122478
Hero Member
*
Offline Offline

Posts: 1540122478

View Profile Personal Message (Offline)

Ignore
1540122478
Reply with quote  #2

1540122478
Report to moderator
lontivero
Full Member
***
Offline Offline

Activity: 157
Merit: 100

Amazing times are coming


View Profile
November 15, 2015, 12:23:38 AM
 #2

Well, there are a couple of things wrong in your code:

  • ASCII encoding: most data in bitcoin is encoded with base58, no ascii.  
  • xpub prefix: it is part of the xPub and you must not remove it.

Now, try this:

Code:
var pubkey = ExtPubKey.Parse("xpub6CUGRUonZSQ4TWtTMmzXdrXDtypWKiKrhko4egpiMZbpiaQL2jkwSB1icqYh2cfDfVxdx4df189oLKnC5fSwqPfgyP3hooxujYzAu3fDVmz");
var newAddress = pubkey.Derive(0).Derive(0).Derive(0).PubKey.GetAddress(Network.Main);
Console.WriteLine(newAddress);


BTW, I recommed you to try things in testnet first.
galgitron
Member
**
Offline Offline

Activity: 63
Merit: 10



View Profile
November 17, 2015, 02:54:14 PM
 #3

That was it Smiley  Much appreciated my friend
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!