Coinstack Open Assets

Bitcoin, which is a representative application using Blockchain, supports a method to transfer not only Bitcoin. Coinstack Open Assets that uses this feature of Bitcoin makes possible to send different types of currency or asset. For example, you can issue a coupon, stock, or voucher using Coinstack Open Assets. This is separated as a layer over Bitcoin, so it inherits the security features of Bitcoin.

1. Protocol

A transaction of Open Assets is generally same as Bitcoin, but only a special output, Marker output. So, if a transaction of Bitcoin has Marker output, it must be Open Assets transaction. Marker output is OP_RETURN transaction start with a special ID, OAP Marker (0x4f41).

OP_RETURN PUSHDATA OAP_MARKER

Additionally, below fields are appended.

Field Description Size
OAP Marker Open Assets Marker, 0x4f41 2 bytes
version number version of Open Asset protocol, 0x0100 2 bytes
Asset quantity count number of asset quantity list in var-integer 1-9 bytes
Asset quantity list list of value of asset encoded by LEB128, value > 0 is integer, and order is same as outputs variable
Metadata length length of meta data in var-integer 1-9 bytes
Metadata meta data variable

2. Address and ID

Open Assets address can be generated from a private key as like as Bitcoin address. You can create Open Assets address like below.

Java
public static String deriveAssetAddressFromPrivateKey(String privateKey)

You can get the Open Assets address from the Bitcoin address.

Java
public static String deriveAssetAddressFromBitcoinAddress(String bitcoinAddress)

You can get the Bitcoin address from the Open Assets address.

Java
public static String deriveBitcoinAddressFromAssetAddress(String assetAddress)

When to issue a new type of asset using Open Assets, Asset ID acts to distinguish an issued asset. Usually, ID is a hash value start with 'A' generated from the first input script of an issued transaction.

RIPEMD160(SHA256(first input script))

This is a method to create an asset id.

Java
public static String createAssetID(byte[] inputScript)

3. Issue Open Assets

This is an example to issue Open Assets with a private key that is a source to generates Open Assets address, the number of asset, a target address, and Bitcoin fee.

Java
public void testIssueAsset() throws Exception {
    String privateKeyWIF = "KyJwJ3Na9fsgvoW2v4rVGRJ7Cnb2pG4yyQQvrGWvkpuovvMRE9Kb";

    long assetAmount = 666;
    String to = "akE2cSu1JuzpXNABPXSrwkWtgL4fiTNq1xz";
    long fee = Math.convertToSatoshi("0.0002");
    String rawTx = coloringEngine.issueAsset(privateKeyWIF, assetAmount, to, fee);

    if (rawTx == null) {
        // Error.
    }

    coinStackClient.sendTransaction(rawTx);
}

4. Transfer Open Assets

This is an example to send a transaction of Open Assets.

Java
public void testTransferAsset() throws Exception {
    String privateKeyWIF = "KztgqWTCKS6dxuUnKcJnyiHtUqJ78k91P8Rn9oNrFLhgnRh3wiiE";

    String assetID = "AKJFoih7ioqPXAHgnDzJvHE8x2FMcFerfv";
    long assetAmount = 30;
    String to = "akFNUeHPC59mrBw3E57bRjgKTdUZeMxeLur";
    long fee = Math.convertToSatoshi("0.0002");
    String rawTx = coloringEngine.transferAsset(privateKeyWIF, assetID, assetAmount, to, fee);

    if (rawTx == null) {
        // Error.
    }

    coinStackClient.sendTransaction(rawTx);
}

results matching ""

    No results matching ""