Objects

In Coinstack API, all transferred data is pretended as Coinstack object. When the API is called, the object should be provided as a parameter, a result of the calling is also the object. Therefore, please check types and attributes of the object in this document.

Various Coinstack objects of APIs are associated with Blockchain data models, so you can grasp easily.

1. BlockchainStatus

This is the object for a status of Blockchain.

Attribute Type Description
best_block_hash string a hash value of the latest block
best_height int the current height of Blockchain, that is, the latest block number

2. Block

This is the object for a status of a block in Blockchain.

Attribute Type Description
block_hash string hash value of block
height int height of block in Blockchain
confirmation_time date confirmed time of the block
parent string hash value of the previous block
children list[string] list of next blocks
transaction_list list[string] list of hash values of transactions in this block

3. Address

Below is objects for Bitcoin address.

3.1. Address Balance

This is the object for which expresses a balance that can be transferred in Satoshi.

Attribute Type Description
balance int balance of address in Satoshi

3.2. Address History

This is the object for a list of hash values of transactions created by the address.

Attribute Type Description
list[string] list of hash value of transactions of address

3.3. Address Unspent Outputs

This is the object for unspent outputs of the address,

Attribute Type Description
transaction_hash string a hash value of the transaction that has the output
index int output index
value string value of output in Satoshi
script string sciprt of output
confirmations int the number of confirmation of this transaction

4. Transaction

This is the object to show an information of a transaction in a block.

Attribute Type Description
transaction_hash string hash value of transaction
block_hash list[string]
block_hash.block_hash string hash value of block hash object
block_hash.block_height int height of block
coinbase boolean is Coinbase transaction?
inputs array[input] array of inputs
outputs array[output] array of outputs
timestamp date approval time of block
initialtimestamp date broadcast time of transaction
addresses int

4.1. Transaction Input

This is the object for a input/inputs, which is/are saved as an array in the transaction object, of a transaction.

Attribute Type Description
transaction_hash int hash value of transaction that has this input as unspent output
output_index int index of unspent output
address list[string] list of addressed associated with this input
value int value of input in Satoshi

4.2. Transaction Output

This is the object for an output/outputs, which is/are saved as an array in the transaction object, of a transaction.

Attribute Type Description
index int
address list[string] list of addressed associated with this output
script string script of output
value int value of output in Satoshi
metadata metadata

5. DataTransactionOutput

Attribute Type Description
index int
used boolean is output used?
script string output의 script
value int value of output in Satoshi
data data data of OP_RETURN

6. Subscription

This is the object to be notified a change of Blockchain.

7. Stamp

This is the object for Document Stamping, which is a service using Coinstack to check whether it is real or not.

Attribute Type Description
stampid string Registered stamp id

APIs

1. Blockchain

This is how to get the current status of Blockchain.

Shell
curl https://mainnet.cloudwallet.io/blockchain \
    -H "apiKey: YOUR_API_TOKEN_KEY"
Java
string[] blockchainstatus = client.getBlockchainStatus();
JavaScript
client.getBlockchainStatus(function(err, status) {
    console.log(status.best_block_hash, status.best_height);
});
Meteor
// server side
var status = client.getBlockchainStatusSync()
console.log(status.best_block_hash, best_height)

// client side
client.getBlockchainStatus(function(err, status) {
    console.log(status.best_block_hash, status.best_height);
});

The result is JSON type.

{
    "best_block_hash": "000000000000000007e5724849ad23a76aa9db734e9671b2b08c075ab017fb6c",
    "best_height": 370353
}

2. Blocks

This is how to get an information of a block.

Shell
YOUR_API_TOKEN_KEY="a1260b79cc3fa142a80ddfebdce232"
YOUR_BLOCK_HASH="0000000000000000035bce787da99a937602b7b47367c1b4b026149eb699df72"

curl https://mainnet.cloudwallet.io/blocks/$YOUR_BLOCK_HASH \
    -H "apiKey: $YOUR_API_TOKEN_KEY"
Java
import io.blocko.coinstack.*

CoinStackClient client = new CoinStackClient();
String your_block_address = "0000000000000000035bce787da99a937602b7b47367c1b4b026149eb699df72"

Block block = client.getBlock(your_block_address);
JavaScript
CoinStackSDK = require("coinstack-sdk-js");

var COINSTACK_ACCESS_KEY="YOUR_COINSTACK_ACCESS_KEY";
var COINSTACK_SECRET_KEY="YOUR_COINSTACK_SECRET_KEY";

client = new CoinStackSDK(COINSTACK_ACCESS_KEY, COINSTACK_SECRET_KEY);

var YOUR_BLOCK_ADDRESS = "0000000000000000035bce787da99a937602b7b47367c1b4b026149eb699df72";

client.getBlock(YOUR_BLOCK_ADDRESS, function(err, result){
    if(!err){
        console.log('result', result);
    }else{
        //fail error processing
    }
});
Meteor
// server side
var YOUR_BLOCK_ADDRESS = "000000000000000007e3d622896e3853eb75427f3b5b366bea8245734b369239";
var result = client.getBlock(YOUR_BLOCK_ADDRESS) {
    console.log('result', result);
});

// client side
var YOUR_BLOCK_ADDRESS = "000000000000000007e3d622896e3853eb75427f3b5b366bea8245734b369239";
client.getBlock(YOUR_BLOCK_ADDRESS, function(err, result) {
    console.log('result', result);
});

The result is JSON type.

{
    block_hash: '000000000000000007e3d622896e3853eb75427f3b5b366bea8245734b369239',
    height: 387326,
    confirmation_time: '2015-12-08T15:18:51Z',
    parent: '00000000000000000bf5295ddd113821d8ab96bd6ba5f695e06eb9083c4b171c',
    children: [ '000000000000000008e214289c87882d3fa9c28694c8d4accf99f434d9be425d' ],
    transaction_list: [ '0caa8d3d7fcbecdefd4466c1806dd6727e8fb30c9f8d1d92fa8026ede6d06f3a' ]
}

3. Addresses

3.1. Get address balance

This is how to get a balance of an address that is expressed as Satoshi, e.g. 0.0001 BTC = 10,000 Satoshi, 1 BTC = 100,000,000 Satoshi.

Shell
curl https://mainnet.cloudwallet.io/addresses/YOUR_WALLET_ADDRESS/balance \
    -H "apiKey: YOUR_API_TOKEN_KEY"
Java
long balance = client.getBalance("YOUR_WALLET_ADDRESS");
JavaScript
client.getBalance("YOUR_WALLET_ADDRESS", function(err, balance) {
    console.log(balance);
});
Meteor
// server
var balance = client.getBalanceSync("YOUR_WALLET_ADDRESS");
console.log(balance);

// client
client.getBalance("YOUR_BLOCKCHAIN_ADDRESS", function(err, balance) {
    if(err){
        console.log(err);
        return;
    }
    console.log(balance);
});

The result is a number.

0

3.2. Get transactions by address

This is how to get a list of transactions of an address.

Shell
curl https://mainnet.cloudwallet.io/addresses/YOUR_WALLET_ADDRESS/history \
    -H "apiKey: YOUR_API_TOKEN_KEY"
Java
String[] transactionIDs = client.getTransactions("YOUR_WALLET_ADDRESS");
JavaScript
client.getTransactions("YOUR_WALLET_ADDRESS", function(err, result) {
    console.log('result', result);
});
Meteor
// server
var result = client.getTransactions("YOUR_WALLET_ADDRESS", function(err, result) {
    console.log('result', result);
});

// client
client.getTransactions("YOUR_WALLET_ADDRESS", function(err, result) {
    if(err){
        console.log(err);
        return;
    }
    console.log('result', result);
});

The result is JSON type.

[
    "900cb2e3ece667c6fa39207299a8d9efebc3356d082efc7b10b5eb8592abc99a",
    "2056162d55cc0e85de0ea85f288941a2a747d33baf0f4c03087a51a69d05309b",
    "dcd14469dd9d5a08186cd97b8711a076fc0aeec80f310488ed980163147c5ebf",
    "559eeaa842220d0d268993d59c19773bd81ce0233c3da1d94f4772f1a7c90bd9",
    "63d404aae3257fda5bed6d5bc0b592015ba04f4ccb1e4dbf7e9475357ba0778c",
    "ea2085282bf0889e16a26fdc7362d6a3cca68849a9f8c6b2de032ef6aa0d02f2",
    "...."
]

3.3. Get unspent outputs by address

This is how to get a list of transactions that have an unspent output(s), which is never used by a different transaction as an input, of an address.

Shell
curl https://mainnet.cloudwallet.io/addresses/YOUR_WALLET_ADDRESS/unspentoutputs \
    -H "apiKey: YOUR_API_TOKEN_KEY"
Java
Output[] unspentOutputs = client.getUnspentOutputs("YOUR_WALLET_ADDRESS");
JavaScript
client.getUnspentOutputs("YOUR_WALLET_ADDRESS", function(err, result) {
    console.log('result', result);
});
Meteor
// server
var result = client.getUnspentOutputs("YOUR_WALLET_ADDRESS") {
    console.log('result', result);
});

// client
client.getUnspentOutputs("YOUR_WALLET_ADDRESS", function(err, result) {
    if(err){
        console.log(err);
        return;
    }
    console.log('result', result);
});

The result is JSON type.

[
    {
        "transaction_hash": "f2020daaf62e03deb2c6f8a94988a6cca3d66273dc6fa2169e88f02b288520ea",
        "index": 1,
        "value": "7259033307",
        "script": "76a914a13ca67f70cc4afefd4057f87d1e433dab05a20788ac",
        "confirmations": 2509
    },
    {
        "transaction_hash": "9b30059da6517a08034c0faf3bd347a7a24189285fa80ede850ecc552d165620",
        "index": 1,
        "value": "299990000",
        "script": "76a914a13ca67f70cc4afefd4057f87d1e433dab05a20788ac",
        "confirmations": 99
    },
    {
        "transaction_hash": "9ac9ab9285ebb5107bfc2e086d35c3ebefd9a899722039fac667e6ece3b20c90",
        "index": 1,
        "value": "961900000",
        "script": "76a914a13ca67f70cc4afefd4057f87d1e433dab05a20788ac",
        "confirmations": 91
    }
]

4. Transactions

4.1. Get transaction

This is how to get an information of a transaction.

Shell
curl https://mainnet.cloudwallet.io/transactions/YOUR_TRANSACTION_ID \
    -H "apiKey: YOUR_API_TOKEN_KEY"
Java
Transaction tx = client.getTransaction("YOUR_TRANSACTION_ID");
JavaScript
client.getTransaction("YOUR_TRANSACTION_ID", function(err, result) {
    console.log('result', result);
});
Meteor
// server
var result = client.getTransaction("YOUR_TRANSACTION_ID") {
    console.log(result.transaction_hash, result.inputs);
});

// client
client.getTransaction("YOUR_TRANSACTION_ID", function(err, result) {
    if(err){
        console.log(err);
        return;
    }
    console.log('result', result);
});

The result is JSON type.

{
    "transaction_hash": "8c14f0db3df150123e6f3dbbf30f8b955a8249b62ac1d1ff16284aefa3d06d87",
    "block_hash": [
        {
            "block_hash": "000000000003ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506",
            "block_height": 100000
        }
    ],
    "coinbase": true,
    "inputs": [
        {
            "transaction_hash": "0000000000000000000000000000000000000000000000000000000000000000",
            "output_index": -1,
            "address": [
            ],
            "value": ""
        }
    ],
    "outputs": [
        {
            "index": 0,
            "address": [
                "1HWqMzw1jfpXb3xyuUZ4uWXY4tqL2cW47J"
            ],
            "value": "5000000000",
            "script": "41041b0e8c2567c12536aa13357b79a073dc4444acb83c4ec7a0e2f99dd7457516c5817242da796924ca4e99947d087fedf9ce467cb9f7c6287078f801df276fdf84ac",
            "used": false
        }
    ],
    "time": "2010-12-29T11:57:43Z",
    "broadcast_time": "0001-01-01T00:00:00Z",
    "addresses": [
        "1HWqMzw1jfpXb3xyuUZ4uWXY4tqL2cW47J"
    ]
}

4.2. Send and Sign

This is how to create a transaction and send it to an address. When sending, a transaction is signed with a private key that would never be sent.

Java
String privateKeyWIF = "MY_PRIVATE_KEY_WIF";
String to = "TO_ADDRESS";

long amount = CoinStackClient.convertToSatoshi("0.0002");
long fee = CoinStackClient.convertToSatoshi("0.0001");
TransactionBuilder builder = new TransactionBuilder();
builder.addOutput(to, amount);
builder.setFee(fee);

String signedTx = coinStackClient.createSignedTransaction(builder, privateKeyWIF);
coinStackClient.sendTransaction(signedTx);
JavaScript
var txBuilder = client.createTransactionBuilder();
txBuilder.addOutput("TO_ADDRESS1", client.Math.toSatoshi("0.01"));
txBuilder.addOutput("TO_ADDRESS2", client.Math.toSatoshi("0.03"));
txBuilder.setInput("MY_WALLET_ADDRESS");
txBuilder.buildTransaction(function(err, tx) {
    tx.sign("MY_PRIVATE_KEY_WIF")
    var rawTx = tx.serialize()
    // send tx
    client.sendTransaction(rawTx, function(err) {
        if (null != err) {
            console.log("failed to send tx");
        }
    );
});
Meteor
// server
var txBuilder = client.createTransactionBuilder();
txBuilder.addOutput("TO_ADDRESS1", client.Math.toSatoshi("0.01"))
txBuilder.addOutput("TO_ADDRESS2", client.Math.toSatoshi("0.03"))
txBuilder.setInput("MY_WALLET_ADDRESS");
var tx = client.buildTransactionSync(txBuilder);
tx.sign("MY_PRIVATE_KEY_WIF")
var rawTx = tx.serialize()

// send tx
try {
    client.sendTransactionSync(rawTx)
} catch (e) {
    console.log("failed to send tx");
}

// client
var txBuilder = client.createTransactionBuilder();
txBuilder.addOutput("TO_ADDRESS1", client.Math.toSatoshi("0.01"))
txBuilder.addOutput("TO_ADDRESS2", client.Math.toSatoshi("0.03"))
txBuilder.setInput("MY_WALLET_ADDRESS");
txBuilder.buildTransaction(function(err, tx) {
    tx.sign("MY_PRIVATE_KEY_WIF")
    var rawTx = tx.serialize()
    // send tx
    client.sendTransaction(rawTx, function(err) {
        if (null != err) {
            console.log("failed to send tx");
        }
    );
})

5. Notification

When a change is occured in Blockchain, you can be notified.

Streamed

This is a active method to notify a connection-oriented transport continuously.

Event hook

This is a passive method to notify. It supports methods; calling HTTP endpoint and Amazon SNS integration. A payload of an event are transferred with JSON type.

This is working in Java SDK only.

5.1. Create

This is to create a subscription to notify.

Subscription newSubscription = new Subscription(
    "YOUR_WALLET_ADDRESS", "YOUR_EXTERNAL_SERVICE_ID");
String subscriptionId = coinStackClient.addSubscription(newSubscription);

5.2. List

This is to call a list of all subscriptions in Coinstack client.

// list previous subscriptions
Subscription[] subscriptions = coinStackClient.listSubscriptions();
System.out.println("listing subscriptions");
for (Subscription subscription : subscriptions) {
    System.out.println(subscription.getId());
    coinStackClient.deleteSubscription(subscription.getId());
}

5.3. Delete

This is to delete a subscription with a id that is used to create.

coinStackClient.deleteSubscription("YOUR_EXTERNAL_SERVICE_ID");

6. Document Stamping

6.1. Stamp document

This is to record a SHA-256 hash value in Blockchain, a stamp id would be returned.

Shell
curl https://mainnet.cloudwallet.io/stamps \
    -H "apiKey: YOUR_API_TOKEN_KEY" \
    -H "Content-Type: application/json" \
    -X POST \
    -d '{"hash" : "YOUR_SHA256_VALUE"}' \
    -v

The result is JSON type.

{ "stampid": "7f902baec17633d12fb70892698157f595682910c96e3ee44cbdc3e2545d6665-2" }

6.2. Get stamp status

This is to check a transaction hash, output, and a status of the confirmation that are stored in Stamp.

Shell
curl https://mainnet.cloudwallet.io/stamps/STAMP_ID \
    -H "apiKey: YOUR_API_TOKEN_KEY"

The result is JSON type.

{
    "tx": "a22c7e42459b91eb325378da4721f53026962b03cd73187549c2e62cb1064464",
    "vout": 0,
    "confirmations": 522,
    "timestamp": "2015-10-30T08:43:42Z"
}

7. Multisig

This is pertinent to create a transaction that needs multiple private keys bigger than a configuration number, e.g. creating a transaction that is agreed when more than six tenth authorities are signed.

Java
// Create a redeem script for multiple signs.
// Only public keys are used for the redeem script, private keys below are expressed to enhance understanding.
String privateKey1 = "private_key_1";
String privateKey2 = "private_key_2";
String privateKey3 = "private_key_3";

String publickey1 = new String(ECKey.derivePubKey(privateKey1));
String publickey2 = new String(ECKey.derivePubKey(privateKey2));
String publickey3 = new String(ECKey.derivePubKey(privateKey3));

List<byte[]> pubkeys = new ArrayList<byte[]>(3);
pubkeys.add(Hex.decodeHex(publickey1.toCharArray()));
pubkeys.add(Hex.decodeHex(publickey2.toCharArray()));
pubkeys.add(Hex.decodeHex(publickey3.toCharArray()));

// for a multisig transaction, create a redeem script.
String redeemScript = MultiSig.createRedeemScript(2, pubkeys);

List<String> prikeys = new ArrayList<String>();
prikeys.add(privateKey1);
prikeys.add(privateKey3);

String to = "the address to get Bitcoin";

long amount = Math.convertToSatoshi("0.0039");
long fee = Math.convertToSatoshi("0.0001");

TransactionBuilder builder = new TransactionBuilder();
builder.addOutput(to, amount);
builder.setFee(fee);

// method 1: sign with private keys together.
String signedTx = coinStackClient.createMultiSigTransaction(builder, prikeys, redeemScript);
System.out.println(signedTx);
coinStackClient.sendTransaction(signedTx);

// method 2: sign with a private key separately. Each user signs one by one.
String signedTx = coinStackClient.createMultiSigTransactionWithPartialSign(builder, privateKey3, redeemScript);
System.out.println(signedTx);
signedTx = coinStackClient.signMultiSigTransaction(signedTx, privateKey2, redeemScript);
coinStackClient.sendTransaction(signedTx);

8. Open Asset

You can use Blockchain to issue a digital asset.

Java
// asset address
String newPrivateKeyWIF = ECKey.createNewPrivateKey();
String bitcoinAddress = ECKey.deriveAddress(newPrivateKeyWIF);

String assetAddress = Address.deriveAssetAddressFromBitcoinAddress(bitcoinAddress);

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

coinStackClient.sendTransaction(rawTx);

// transfer
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 ""