Transferring an asset

So now, let’s imagine I sent you some BlockchainProgramming Coins. How can you send me back the coins? You need to build a ColoredCoin.

In the sample above, let’s say I want to spend the 10 assets I received on the address “nico”. Here is the coin I want to spend:

{
  "transactionId": "fa6db7a2e478f3a8a0d1a77456ca5c9fa593e49fd0cf65c7e349e5a4cbe58842",
  "index": 0,
  "value": 600,
  "scriptPubKey": "76a914356facdac5f5bcae995d13e667bb5864fd1e7d5988ac",
  "redeemScript": null,
  "assetId": "AVAVfLSb1KZf9tJzrUVpktjxKUXGxUTD4e",
  "quantity": 10
}

Here is how to instantiate such Colored Coin in code:

var coin = new Coin(
    fromTxHash: new uint256("fa6db7a2e478f3a8a0d1a77456ca5c9fa593e49fd0cf65c7e349e5a4cbe58842"),
    fromOutputIndex: 0,
    amount: Money.Satoshis(600),
    scriptPubKey: new Script(Encoders.Hex.DecodeData("76a914356facdac5f5bcae995d13e667bb5864fd1e7d5988ac")));
BitcoinAssetId assetId = new BitcoinAssetId("AVAVfLSb1KZf9tJzrUVpktjxKUXGxUTD4e");
ColoredCoin colored = coin.ToColoredCoin(assetId, 10);

We will show you later how you can use some web services or custom code to get the coins more easily. I also needed another coin (forFees), to pay the fees. The asset transfer is actually very easy with the TransactionBuilder.

Which basically succeed:

Last updated