create account

Gridcoin HUG REST API by cm-steem

View this thread on: hive.blogpeakd.comecency.com
· @cm-steem ·
$12.00
Gridcoin HUG REST API
![](https://steemitimages.com/DQmajWZo7M3uWN5ku1jJsF3RndzTfzZwpYKiTpXQFuVCwxA/GRCHorizontal_Purple%26Purple_Solid.png)

# Gridcoin HUG REST API

The purpose of the Gridcoin HUG REST API is to provide an open-source high performance interface to the Gridcoin network through simple GET requests.

By following this guide, you can easily recreate the API in your own control. Do remember to change the API key and rpc details you've configured in the gridcoinresearch.conf file.

You can find the code within the [Gridcoin-Community github org](https://github.com/gridcoin-community/GRC-HUG-REST-API).

### About: HUG

> ##### Embrace the APIs of the future
> Drastically simplify API development over multiple interfaces. With hug, design and develop your API once, then expose it however your clients need to consume it. Be it locally, over HTTP, or through the command line - hug is the fastest and most modern way to create APIs on Python3.
> ##### Unparalleled performance
> hug has been built from the ground up with performance in mind. It is built to consume resources only when necessary and is then compiled with Cython to achieve amazing performance. As a result, hug consistently benchmarks as one of the fastest Python frameworks and without question takes the crown as the fastest high-level framework for Python 3.
>
> Source: [Official website](http://www.hug.rest/).

---

## Install guide

This is an install guide for Ubuntu 17.10. The HUG REST API uses Python3, HUG, Gunicorn & NGINX. If you change the OS or server components then the following guide will be less applicable, if you succeed please do provide a separate readme for alternative implementation solutions.

### Setup dependencies & Python environment

We create the 'grcapi' user, however you could rename this to whatever you want, just remember to change the NGINX & Gunicorn configuration files.

#### Setup a dedicated user

    adduser grcapi
    <ENTER NEW PASSWORD>
    <CONFIRM NEW PASSWORD>
    usermod -aG sudo grcapi
    sudo usermod -a -G www-data grcapi
    su - grcapi

#### Install required applications

    sudo apt-get install libffi-dev libssl-dev python3-pip python3-dev build-essential git nginx python3-setuptools virtualenv libcurl4-openssl-dev

#### Create Python virtual environment

    mkdir HUG
    virtualenv -p python3 HUG
    echo "source ./HUG/bin/activate" > access_env.sh
    chmod +x access_env.sh
    source access_env.sh

#### Install Python packages

    pip3 install --upgrade pip
    pip3 install --upgrade setuptools
    pip3 install --upgrade wheel
    pip3 install requests
    pip3 install hug
    pip3 install gunicorn
    pip3 install json

### Configure NGINX

NGINX serves as a reverse web proxy to Gunicorn & uses an UNIX socket instead of an IP address for referencing Gunicorn.

    Copy the nginx.conf file to /etc/nginx/
    Reset nginx (sudo service nginx restart)

    sudo mv default /etc/nginx/sites-available/default

### Implement SSL Cert

You aught to implement a free LetsEncrypt SSL certificate, this requires a domain name (they don't sign IP addresses) and it needs to be renewed every few months by running certbot again. NOTE: Replace ```api.domain.tld``` with your own full domain path.

https://certbot.eff.org/

    sudo add-apt-repository ppa:certbot/certbot
    sudo apt-get update
    sudo apt-get install python-certbot-nginx
    sudo certbot --nginx -d api.domain.tld

### Configure Gunicorn

Official website: http://gunicorn.org/

Documentation: http://docs.gunicorn.org/en/stable/

Gunicorn is used to provide scalable worker process management and task buffering for the HUG REST API. Gunicorn's documentation states that each CPU can provide roughly 2-3+ Gunicorn workers, however it may be able to achieve a higher quantity (worth testing).

    cp gunicorn.service /etc/systemd/system/gunicorn.service
    sudo systemctl start gunicorn
    sudo systemctl enable gunicorn

### MISC

If you make changes to the service or the hug script:

    sudo systemctl daemon-reload
    sudo systemctl restart gunicorn

If you want to monitor Gunicorn:

    tail -f gunicorn_access_log
    tail -f gunicorn_error_log
    sudo systemctl status gunicorn

---

# Available HUG REST API functionality

This section will detail the functionality which will be available to the public through GET requests.

The functions are currently all read-only functions, enabling the public to request data from the network without the risk of exposing critical wallet controls.

## grc_command

All GRC functions which don't require any input parameters can be called through this function.

### Parameters

#### function `string`

```
beaconreport
currentneuralhash
currentneuralreport
getmininginfo
neuralreport
superblockage
upgradedbeaconreport
validcpids
getbestblockhash
getblockchaininfo
getblockcount
getconnectioncount
getdifficulty
getinfo
getnettotals
getnetworkinfo
getpeerinfo
getrawmempool
listallpolldetails
listallpolls
listpolldetails
listpolls
networktime
getwalletinfo
```

#### api_key `string`

#### Usage
`https://subdomain.domain.tld/grc_command?api_key=123abc&function=getinfo`

---

Have a need for the GRC HUG REST API? Or have any questions about the project, post a reply below!
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
properties (23)
authorcm-steem
permlinkgridcoin-hug-rest-api
categorygridcoin
json_metadata{"tags":["gridcoin","beyondbitcoin","cryptocurrency","programming","crypto"],"image":["https://steemitimages.com/DQmajWZo7M3uWN5ku1jJsF3RndzTfzZwpYKiTpXQFuVCwxA/GRCHorizontal_Purple%26Purple_Solid.png"],"links":["https://github.com/gridcoin-community/GRC-HUG-REST-API","http://www.hug.rest/","https://certbot.eff.org/","http://gunicorn.org/","http://docs.gunicorn.org/en/stable/"],"app":"steemit/0.1","format":"markdown"}
created2018-07-18 22:58:21
last_update2018-07-18 22:58:21
depth0
children4
last_payout2018-07-25 22:58:21
cashout_time1969-12-31 23:59:59
total_payout_value10.042 HBD
curator_payout_value1.953 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length5,242
author_reputation58,522,774,254,119
root_title"Gridcoin HUG REST API"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id65,170,247
net_rshares5,729,185,382,637
author_curate_reward""
vote details (64)
@sau412 ·
$0.36
What is use case for this?
👍  , ,
properties (23)
authorsau412
permlinkre-cm-steem-gridcoin-hug-rest-api-20180719t113459233z
categorygridcoin
json_metadata{"tags":["gridcoin"],"app":"steemit/0.1"}
created2018-07-19 11:35:00
last_update2018-07-19 11:35:00
depth1
children1
last_payout2018-07-26 11:35:00
cashout_time1969-12-31 23:59:59
total_payout_value0.273 HBD
curator_payout_value0.088 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length26
author_reputation8,198,119,818,978
root_title"Gridcoin HUG REST API"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id65,231,291
net_rshares171,935,037,466
author_curate_reward""
vote details (3)
@cm-steem ·
$0.02
It can be used to provide real-time client data to the public behind nginx & gunicorn - handy for scripting projects & better than exposing the Gridcoin client directly to the public.

Only read-only commands have been implemented due to risk of abuse, however they could be easily implemented.

It also [downloads, processes and outputs the project user xml gz files to json, msgpack and protobuffer](https://steemit.com/gridcoin/@cm-steem/boinc-user-xml-data-serialization-comparison) files - these can be used by anyone for POR projects.
👍  ,
properties (23)
authorcm-steem
permlinkre-sau412-re-cm-steem-gridcoin-hug-rest-api-20180719t150218317z
categorygridcoin
json_metadata{"tags":["gridcoin"],"links":["https://steemit.com/gridcoin/@cm-steem/boinc-user-xml-data-serialization-comparison"],"app":"steemit/0.1"}
created2018-07-19 15:02:15
last_update2018-07-19 15:02:15
depth2
children0
last_payout2018-07-26 15:02:15
cashout_time1969-12-31 23:59:59
total_payout_value0.019 HBD
curator_payout_value0.004 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length540
author_reputation58,522,774,254,119
root_title"Gridcoin HUG REST API"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id65,253,448
net_rshares11,585,244,279
author_curate_reward""
vote details (2)
@steemmillionaire · (edited)
$0.08
This is something I definitely want to look into, for some automation ideas on the Gridcoin blockchain. Thank you @cm-steem!
👍  , ,
properties (23)
authorsteemmillionaire
permlinkre-cm-steem-gridcoin-hug-rest-api-20180720t134616726z
categorygridcoin
json_metadata{"tags":["gridcoin"],"users":["cm-steem"],"app":"steemit/0.1"}
created2018-07-20 13:46:18
last_update2018-07-20 13:46:42
depth1
children0
last_payout2018-07-27 13:46:18
cashout_time1969-12-31 23:59:59
total_payout_value0.059 HBD
curator_payout_value0.017 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length124
author_reputation127,790,992,179,371
root_title"Gridcoin HUG REST API"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id65,367,095
net_rshares36,423,423,314
author_curate_reward""
vote details (3)
@verifyme ·
@cm-steem You have received a 100% upvote from @steemprotector because this post did not use any bidbots and you have not used bidbots in the last 30 days!

Upvoting this comment will help keep this service running.
properties (22)
authorverifyme
permlinkre-gridcoin-hug-rest-api-cm-steem-verifyme-randomvote
categorygridcoin
json_metadata{"tags":["verifyme","random-upvote"],"users":["cm-steem","steemprotector"],"app":"null/null","format":"markdown"}
created2018-07-19 23:28:09
last_update2018-07-19 23:28:09
depth1
children0
last_payout2018-07-26 23:28:09
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length217
author_reputation-705,247,747,464
root_title"Gridcoin HUG REST API"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id65,297,771
net_rshares0