Back to all updates

almost 7 years ago

Did you know?! Fun Hack Fact Friday

Did you know?!

Bitcoin Addresses are composed of a version byte which identifies the network where to use the address and the hash of a public key. So we can go backwards and generate a bitcoin address from the ScriptPubKey and the network identifier.

var paymentScript = publicKeyHash.ScriptPubKey;
var sameMainNetAddress = paymentScript.GetDestinationAddress(Network.Main);
Console.WriteLine(mainNetAddress == sameMainNetAddress); // True

It is also possible to retrieve the hash from the ScriptPubKey and generate a Bitcoin Address from it:

var samePublicKeyHash = (KeyId) paymentScript.GetDestination();
Console.WriteLine(publicKeyHash == samePublicKeyHash); // True
var sameMainNetAddress2 = new BitcoinPubKeyAddress(samePublicKeyHash, Network.Main);
Console.WriteLine(mainNetAddress == sameMainNetAddress2); // True

Note: A ScriptPubKey does not necessarily contain the hashed public key(s) permitted to spend the bitcoin.

Check out the full post regarding the ScriptPubKey and more!

Questions?

If you have any questions about the hackathon, please post on the discussion forum.