Issuing an asset
Objective
For the purpose of this exercise, I will emit BlockchainProgramming coins.
You get one of these BlockchainProgramming coins for every 0.004 bitcoin you send me. One more if you add some kind words. Furthermore this is a great opportunity to make it to the Hall of The Makers.
Let’s see how I would code such feature.
Issuance Coin
In Open Asset, the Asset ID is derived from the issuer's ScriptPubKey. If you want to issue a Colored Coin, you need to prove ownership of such ScriptPubKey. And the only way to do that on the Blockchain is by spending a coin belonging to such ScriptPubKey.
The coin that you will choose to spend for issuing colored coins is called “Issuance Coin” in NBitcoin. I want to emit an Asset from the book bitcoin address: 1KF8kUVHK42XzgcmJF4Lxz4wcL5WDL97PB.
Take a look at my balance, I decided to use the following coin for issuing assets.
Here is how to create my issuance coin:
Now I need to build transaction and sign the transaction with the help of the TransactionBuilder.
You can see it includes an OP_RETURN output. In fact, this is the location where information about colored coins are stuffed.
Here is the format of the data in the OP_RETURN.
In our case, Quantities have only 10, which is the number of Asset I issued to nico
. Metadata is arbitrary data. We will see that we can put an url that points to an “Asset Definition”.
An Asset Definition is a document that describes what the Asset is. It is optional, we are not using it in our case. (We’ll come back later on it in the Ricardian Contract part.)
For more information check out the Open Asset Specification.
After transaction verifications it is ready to be sent to the network.
With QBitNinja
Or with local Bitcoin core
My Bitcoin Wallet have both, the book address and the “Nico” address.
As you can see, Bitcoin Core only shows the 0.0001 BTC of fees I paid, and ignore the 600 Satoshi coin because of spam prevention feature.
This classical bitcoin wallet knows nothing about Colored Coins. Worse: If a classical bitcoin wallet spend a colored coin, it will destroy the underlying asset and transfer only the bitcoin value of the TxOut. (600 satoshi)
For preventing a user from sending Colored Coin to a wallet that do not support it, Open Asset have its own address format, that only colored coin wallets understand.
Now, you can take a look on an Open Asset compatible wallet like Coinprism, and see my asset correctly detected:
As I have told you before, the Asset ID is derived from the issuer’s ScriptPubKey, here is how to get it in code:
Last updated