API

All requests are sent by POST method to the following URL: https://faucet.cryptonex.org/api/jsonrpc

Curl Example

        
        curl -i -X POST -H "Content-Type: application/json; indent=4" -d '{ "jsonrpc": "2.0", "method": "coin.get", "params": { "address": "mnCxoseek8b93wGzztF4RM97vU3XqAfQ4u", "coins": "10" }, "id": "1" }' https://faucet.cryptonex.org/api/jsonrpc
        
    

Methods

Method name coin.get
Params

address – your cryptoaddress;

coins – the number of coins, optional parameter, takes values from 1 to 10 inclusively; if there is no value or a value is specified out of the range, it automatically becomes 10

Example

{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "coin.get",
    "params": {
        "address": "mnCxoseek8b93wGzztF4RM97vU3XqAfQ4u",
        "coins": "42"
    }
}

Response success

{
    "jsonrpc": "2.0",
    "id": "1",
    "result": {
        "txid": "c26c7c01645bc98dbc763ecf5ca5ac0154b82a0236978a3135c012ea0da4fb1f"
    }
}

Response error

// When the last transaction has not passed within 24 hours


{
    "jsonrpc": "2.0",
    "id": "1",
    "result": {
        "address": "mnCxoseek8b93wGzztF4RM97vU3XqAfQ4u",
        "coins": 10.0,
        "datetime": "Sat, 01 Sep 2018 15:10:31 GMT",
        "message": "You can receive coins only once a day",
        "source": "127.0.0.1",
        "txid": "2485a2406d5409f02b2ef893f041a55e8bb4535ec09535f1cf22a44523324c08"
    }
}

// When the method does not exist


{
    "jsonrpc":"2.0",
    "id":"1",
    "error": {
        "code": -32601,
        "data": null,
        "message": "MethodNotFoundError: Method not found. Available methods: system.describe\ncoin.get",
        "name": "MethodNotFoundError"
    }
}

Example for a Python client


import requests
import json
import sys


def coin_get(address, coins=10):
    url = "https://faucet.cryptonex.org/api/jsonrpc"
    headers = {'content-type': 'application/json'}
    payload = {
        "jsonrpc": "2.0",
        "id": 1,
        "method": "coin.get",
        "params": {
            "address": address,
            "coins": str(coins)
        }
    }
    response = None

    try:
        response = requests.post(url, data=json.dumps(
            payload), headers=headers)
    except Exception:
        print('Error connection')
        return False

    if response.status_code == requests.codes.ok:
            response =response.json()
            if "error" in response.keys():
                print(response["error"]["message"])
                return False
            else:
                print(response["result"]["message"])
                print('txid:', response["result"]["txid"])
                return response["result"]["txid"]
    else:
        print('Error code:', response.status_code)
        return False
        

if __name__ == '__main__':
    if len(sys.argv) <= 1 or len(sys.argv) > 3:
        print('Usage: cnxtest.py <CNX testnet address> [amount]')
        exit(0)

    amount = 10

    if len(sys.argv) == 3:
        amount = int(sys.argv[2])

    if amount <= 0:
        print('Wrong amount')

    coin_get(sys.argv[1], amount)