Skip to content

DamianSuess/Test.CryptoCoins

Repository files navigation

Xeno CryptoCoins Test App

Introduction

This sample aims to follow the Programming Blockchain guide and apply it to Xamarin.Forms.

The repo will be updated in segments as we follow along with the NBitcoin guide, providing the community with a sample of how you can apply this in our own projects

Testing

There are two Bitcoin networks:

  • TestNet is a Bitcoin network for development purposes. Bitcoins on this network worth nothing.
  • MainNet is the Bitcoin network everybody uses.

Usage

Your Bitcoin Address is what your share to the world to get paid. And your wallet uses a private key to spend the money you receive on this address.

Generate a private key

Key privateKey = new Key();  // Get random private key

From this we can generate a public key

PubKey publicKey = privateKey.PubKey;
Console.WriteLine(publicKey); // 0251036303164f6c458e9f7abecb4e55e5ce9ec2b2f1d06d633c9653a07976560c

Get your Bitcoin Address

// 1PUYsjwfNmX64wS368ZR5FMouTtUmvtmTY
var addr = publicKey.GetAddress(Network.Main);
Console.WriteLine(addr);

// n3zWAo2eBnxLr3ueohXnuAa8mTVBhxmPhq
var testAddr = publicKey.GetAddress(Network.TestNet);
Console.WriteLine(testAddr);

A bitcoin address is made up of a version byte. These bytes are concatenated and then encoded into a Base58Check

var publicKeyHash = publicKey.Hash;
Console.WriteLine(publicKeyHash); // f6889b21b5540353a29ed18c45ea0031280c42cf
var mainNetAddress = publicKeyHash.GetAddress(Network.Main);
var testNetAddress = publicKeyHash.GetAddress(Network.TestNet);

Fact: A public key hash is generated by using a SHA256 hash on the public key, then a RIPEMD160 hash on the result, using Big Endian notation. The function could look like this: RIPEMD160(SHA256(pubkey))

The Base58Check encoding has checksums to prevent typos, and lack ambiguous characters like 0 and O.

Console.WriteLine(mainNetAddress); // 1PUYsjwfNmX64wS368ZR5FMouTtUmvtmTY
Console.WriteLine(testNetAddress); // n3zWAo2eBnxLr3ueohXnuAa8mTVBhxmPhq

Coming Soon!

References

About

Sample using Xamarin.Forms and NBitcoin

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages