NAV
shell javascript

Introduction

Welcome to the Chain.Cloud API!

Our API endpoints are located here: https://api.chain.cloud.

Please make sure you always work through HTTPS to avoid Man-in-the-middle attacks.

Authentication

Get Auth Token

var email = encodeUrl('your-email@mail.com');
var url = 'https://api.chain.cloud:8080/users/' + email + '/login/v1';

var j = {
     pass: '12345'
};
var data = JSON.stringify(j);

postData(url,data,function(err,statusCode,h,dataOut){
     assert.equal(err,null);
     assert.equal(statusCode,200);

     var parsed = JSON.parse(dataOut);

     // Get token
     assert.notEqual(parsed.token.length,0);

     done();
});
curl -H "Content-Type: application/json"
     -X POST -d '{"pass": "12345"}'
     "https://api.chain.cloud:8080/users/tony%40mail.com/login/v1"

The above command returns JSON structured like this:

{
     "token": "123123123131231",
     "shortId": "800684244"
}

This endpoint retrieves Auth Token. To get Password - please contact us.

HTTP Request

POST https://api.chain.cloud:8080/users/:EMAIL/login/v1

URL Parameters

Parameter Description
EMAIL Your email

Body

Parameter Description
pass Your password

Documents

Add document to BlockChain

var url = 'https://api.chain.cloud:8080/auth/users/' + userId + '/docs/v1';

// your document sha256 calculated on your side
var sha256 = 'ce7a3e4c5d80cb633c94623b3b07aa1391d1a2186f3439fbe1184a0be440284f';

var j = {
     hash: sha256,
     blockchainType: 1
};
var data = JSON.stringify(j);

postDataWithAuth(url,data,globalToken,function(err,statusCode,h,dataOut){
     assert.equal(err,null);
     assert.equal(statusCode,200);

     var parsed = JSON.parse(dataOut);
     console.log('DOC created result: ',parsed);

     assert.notEqual(parsed.txHash.length,0);
     assert.notEqual(parsed.infoLink.length,0);

     done();
});
curl -H "Content-Type: application/json"
     -H "Authorization: Bearer YOUR-AUTH-TOKEN-HERE"
     -X POST -d '{"hash": "12345", "blockchainType":"1"}'
     "https://api.chain.cloud:8080/users/3456789/docs/v1"

The above command returns JSON structured like this:

{
     "txHash": "2509e5b65ed362557fcf2104e89f3c2430ceecc6a3275556c1b966eb641fe092",
     "infoLink":"https://live.blockcypher.com/btc/tx/2509e5b65ed362557fcf2104e89f3c2430ceecc6a3275556c1b966eb641fe092/"
}

This endpoint adds document hash to BlockChain. It generates new Transaction.

HTTP Request

POST https://api.chain.cloud:8080/auth/users/:ID/docs/v1

HTTP Headers

Header Value
Content-Type Must be set to ‘application/json’
Authorization Must be set to 'Bearer YOUR-AUTH-TOKEN-HERE’

URL Parameters

Parameter Description
ID Your user ID, that is returned while Authenticating

Body

Parameter Description
hash SHA-256 hash of your document
blockchainType BlockChain type. Must be set to 1 for BTC Main net
docName (optional) document name
docDate (optional) document date
docSize (optional) document size

Get document info

// your document sha256 calculated on your side
var sha256 = 'ce7a3e4c5d80cb633c94623b3b07aa1391d1a2186f3439fbe1184a0be440284f';

var url = 'https://api.chain.cloud:8080/auth/users/' + userId + '/docs/' + sha256 + '/v1';

getDataWithAuth(url,globalToken,function(err,statusCode,h,dataOut){
     assert.equal(err,null);
     assert.equal(statusCode,200);

     var parsed = JSON.parse(dataOut);

     // Check doc info:
     assert.equal(parsed.confirms,0);
     assert.notEqual(parsed.block_index,0);

     done();
});
curl -H "Authorization: Bearer YOUR-AUTH-TOKEN-HERE"
     "https://api.chain.cloud:8080/users/456789/docs/ce7a3e4c5d80cb633c94623b/v1"

The above command returns JSON structured like this:

{
     "blockchainType":"1",
     "infoLink":"https://live.blockcypher.com/btc/tx/2509e5b65ed362557fcf2104e89f3c2430ceecc6a3275556c1b966eb641fe092/",
     "txHash": "2509e5b65ed362557fcf2104e89f3c2430ceecc6a3275556c1b966eb641fe092",
     "docName": "one.jpg",
     "docSize": "1231231",
     "docDate": "12-jan-2016",
     "confirms": "1",
     "block_index": "67421"
}

This endpoint gets document info.

HTTP Request

GET https://api.chain.cloud:8080/auth/users/:ID/docs/:DOC_HASH/v1

HTTP Headers

Header Value
Content-Type Must be set to 'application/json’
Authorization Must be set to 'Bearer YOUR-AUTH-TOKEN-HERE’

URL Parameters

Parameter Description
ID Your user ID, that is returned while Authenticating
DOC_HASH SHA-256 hash of your document

Transactions

Get Transaction info

var txHash = '540c90560935d963c0d70e3798822fa49dd422c49e874f954ffd01c69d539d15';

var url = 'https://api.chain.cloud:8080/auth/users/' + userId + '/tx/' + txHash + '/v1';

getDataWithAuth(url,globalToken,function(err,statusCode,h,dataOut){
     assert.equal(err,null);
     assert.equal(statusCode,200);

     var parsed = JSON.parse(dataOut);

     // Check doc info:
     assert.equal(parsed.confirms,0);
     assert.notEqual(parsed.block_index,0);

     done();
});
curl -H "Authorization: Bearer YOUR-AUTH-TOKEN-HERE"
     "https://api.chain.cloud:8080/users/456789/tx/540c90560935d963c0d70e3798822fa49dd422c49e874f954ffd01c69d539d15/v1"

The above command returns JSON structured like this:

{
     "confirms": "1",
     "block_index": "67421"
}

This endpoint gets TX info.

HTTP Request

GET https://api.chain.cloud:8080/auth/users/:ID/tx/:TX_HASH/v1

HTTP Headers

Header Value
Content-Type Must be set to ‘application/json’
Authorization Must be set to 'Bearer YOUR-AUTH-TOKEN-HERE’

URL Parameters

Parameter Description
ID Your user ID, that is returned while Authenticating
TX_HASH Transaction hash

Errors

Chain.Cloud API uses the following error codes:

Error Code Meaning
400 Bad Request – Your request sucks
401 Unauthorized – Your API key is wrong
403 Forbidden – The kitten requested is hidden for administrators only
404 Not Found – The specified kitten could not be found
500 Internal Server Error – We had a problem with our server. Try again later.
503 Service Unavailable – We’re temporarially offline for maintanance. Please try again later.