True API endpoints

Save hash to the blockchain.

Use POST https://trueapi.co/v1/hash/ HTTP request. Assuming request has finished successfully, your data will be stored to selected blockchains.

parameters:

  • hash - a sha256 hash of your file.
  • blockchains - a comma-separated list of blockchains to use. Currently supported: eulercoin_testnet.

Command-line example:

$ curl -X POST \
  https://trueapi.co/v1/hash/ \
  -d "hash=2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824&blockchains=eulercoin_testnet" \
  --header "Accept: application/json; indent=4"

output:

{
    "blockchains": {
        "eulercoin_testnet": {
            "transaction_hash": "586afa9bc302fe01c00c83b931e6699dbb064181818c35f4aae61c245b817c88",
            "links": {
                "transaction": "https://blockchain.testnet.eulercoin.org/tx/586afa9bc302fe01c00c83b931e6699dbb064181818c35f4aae61c245b817c88",
            }
        }
    },
    "proof": "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"
}

proof can be used to retrieve additional information about your request status.

Get status of your blockchain proof by proof.

While POST /v1/hash/ guarantee you data will be saved to blockchain, this can be useful to verify that your data has been saved on selected blockchains at this moment of time, and check for additional information like block number and block hash.

Command-line example:

$ curl -X GET \
  https://trueapi.co/v1/status/2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa742e73043362938b9824/ \
  --header "Accept: application/json; indent=4"

Output:

{
    "blockchains": {
        "eulercoin_testnet": {
            "status": "ready",
            "links": {
                "transaction": "https://blockchain.testnet.eulercoin.org/tx/586afa9bc302fe01c00c83b931e6699dbb064181818c35f4aae61c245b817c88",
                "block": "https://blockchain.testnet.eulercoin.org/block/0026318158dc24a791c8d8442f83edae579e582661d890d7fc8be36fcb8bb036"
            },
            "transaction_hash": "586afa9bc302fe01c00c83b931e6699dbb064181818c35f4aae61c245b817c88",
            "block_height": 136789,
            "block_hash": "0026318158dc24a791c8d8442f83edae579e582661d890d7fc8be36fcb8bb036",
        }
    },
    "proof": "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"
}

Examples

download example
#!/usr/bin/env python
import sys
import requests
from hashlib import sha256
from pprint import pprint, pformat

# Get file hash
if len(sys.argv) < 2:
    print("Specify input file as 1st parameter.")
    sys.exit(1)
file_name = sys.argv[1]
file_hash = sha256(open(file_name, 'rb').read()).hexdigest()

# Send the hash to blockchain
response = requests.post('https://trueapi.co/v1/hash/', {
    'hash': file_hash,
    'blockchains': 'eulercoin_testnet',
})
if response.status_code in {200, 201}:
    proof = response.json()['proof']
    open('proof.output', 'w').write("file_name: {}\nhash: {}\nproof: {}\nserver response:\n{}\n".format(file_name, file_hash, proof, pformat(response.json())))
elif response.status_code == 400:
    print('Please fix request parameters:', pformat(response.json()))
    sys.exit(1)
else:
    print('Error:', response.status_code)
    sys.exit(1)

# Check status of the hash
response = requests.get('https://trueapi.co/v1/status/{}/'.format(proof))
if response.status_code in {200, 201}:
    status = response.json()['blockchains']['eulercoin_testnet']['status']
    open('status.output', 'w').write("status: {}\nserver response:\n{}\n".format(status, pformat(response.json())))
else:
    print('Error:', response.status_code)
    sys.exit(1)
    
# Check status of the non existing proof
response = requests.get('https://trueapi.co/v1/status/{}/'.format('772efcfdc5d3...'))
if response.status_code == 404:
    open('non_existing_status.output', 'w').write("Status code: {}\nserver response:\n{}\n".format(response.status_code, pformat(response.json())))
else:
    print('Error:', response.status_code)
    sys.exit(1)

print("Done.")
print("Check out 'proof.output', 'status.output', and 'non_existing_status.output'")
download example
#!/usr/bin/env python
import sys
import json
from hashlib import sha256
from pprint import pprint, pformat

if sys.version_info[0] >= 3:
    from urllib.request import urlopen
    from urllib.parse import urlencode
    from urllib.error import HTTPError, URLError
else:
    from urllib import urlencode    
    from urllib2 import urlopen
    from urllib2 import HTTPError


# Get file hash
if len(sys.argv) < 2:
    print("Specify input file as 1st parameter.")
    sys.exit(1)
file_name = sys.argv[1]
file_hash = sha256(open(file_name, 'rb').read()).hexdigest()

# Send the hash to blockchain
try:
    response = urlopen('https://trueapi.co/v1/hash/', urlencode({
        'hash': file_hash,
    }).encode('utf-8'))
    data = json.load(response)
    proof = data['proof']
    open('proof.output', 'w').write("file_name: {}\nhash: {}\nproof: {}\nserver response:\n{}\n".format(
        file_name, file_hash, proof, pformat(data)
    ))
except HTTPError as e:
    if e.code == 400:
        pprint("Please fix request fields:", json.load(e))
    else:
        print('Error:', e.code)
    sys.exit(1)
except URLError as e:
    print('We failed to reach a server. Reason: ', e.reason)
    sys.exit(1)

# Check status of the hash
try:
    response = urlopen('https://trueapi.co/v1/status/{}/'.format(proof))
    data = json.load(response)
    status = data['blockchains']['eulercoin_testnet']['status']
    open('status.output', 'w').write("status: {}\nserver response:\n{}\n".format(status, pformat(data)))
except HTTPError as e:
    print('Error:', e.code)
    sys.exit(1)
except URLError as e:
    print('We failed to reach a server. Reason: ', e.reason)
    sys.exit(1)

# Check status of non existing proof
bad_proof = 'ae8b70954e...'
try:
    response = urlopen('https://trueapi.co/v1/status/{}/'.format(bad_proof))
except HTTPError as e:
    if e.code == 404:
        data = json.load(e)
        open('non_existing_status.output', 'w').write("Status code: {}\nserver response:\n{}\n".format(e.code, pformat(data)))
    else:
        print('Error:', e.code)
        sys.exit(1)
except URLError as e:
    print('We failed to reach a server. Reason: ', e.reason)
    sys.exit(1)

print("Done.")
print("Check out 'proof.output', 'status.output', and 'non_existing_status.output'")
© 2016 True Group Inc. All Right Reserved