 # 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!
author | cm-steem |
---|---|
permlink | gridcoin-hug-rest-api |
category | gridcoin |
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"} |
created | 2018-07-18 22:58:21 |
last_update | 2018-07-18 22:58:21 |
depth | 0 |
children | 4 |
last_payout | 2018-07-25 22:58:21 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 10.042 HBD |
curator_payout_value | 1.953 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 5,242 |
author_reputation | 58,522,774,254,119 |
root_title | "Gridcoin HUG REST API" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 65,170,247 |
net_rshares | 5,729,185,382,637 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
scalextrix | 0 | 32,615,094,293 | 100% | ||
cm-steem | 0 | 545,271,022,652 | 100% | ||
on0tole | 0 | 138,167,772,468 | 100% | ||
vortac | 0 | 3,482,199,904,351 | 100% | ||
zaebars | 0 | 442,808,656,971 | 100% | ||
smailer | 0 | 353,842,837,535 | 100% | ||
erikkartmen | 0 | 2,216,466,395 | 100% | ||
neuralminer | 0 | 3,146,860,917 | 100% | ||
sc-steemit | 0 | 73,036,988,250 | 100% | ||
peppernrino | 0 | 15,886,055,689 | 100% | ||
profitgenerator | 0 | 51,103,995 | 100% | ||
happyhippy87 | 0 | 1,430,257,533 | 100% | ||
rusteemitblog | 0 | 97,751,775,128 | 100% | ||
steemtruth | 0 | 4,706,206,529 | 15% | ||
barton26 | 0 | 9,774,172,384 | 100% | ||
marel | 0 | 27,336,667,568 | 100% | ||
minersean | 0 | 0 | 100% | ||
wilbur | 0 | 38,856,009,067 | 100% | ||
spacecowboy | 0 | 1,999,172,644 | 100% | ||
blockained | 0 | 1,077,123,265 | 100% | ||
blockchained | 0 | 236,333,844,310 | 100% | ||
marco.world | 0 | 1,077,087,042 | 100% | ||
sodom | 0 | 2,474,516,951 | 100% | ||
blckchnd | 0 | 1,232,355,105 | 100% | ||
vikx | 0 | 7,199,377,128 | 100% | ||
vadbars | 0 | 66,611,362 | 100% | ||
cm-mobile | 0 | 1,404,848,254 | 100% | ||
kiebitz | 0 | 4,527,132,880 | 100% | ||
screenwriterml | 0 | 6,813,539,852 | 51% | ||
grider123 | 0 | 1,507,922,853 | 100% | ||
jkkim | 0 | 76,723,970 | 10% | ||
diogogomes | 0 | 478,897,295 | 85% | ||
theissen | 0 | 1,941,646,581 | 100% | ||
xxcynicalkidxx | 0 | 211,876,554 | 50% | ||
crt | 0 | 18,541,779,647 | 100% | ||
zipity | 0 | 3,363,817,305 | 100% | ||
unrared | 0 | 13,863,591,971 | 20% | ||
trixiedraws | 0 | 4,136,457,521 | 100% | ||
parejan | 0 | 9,801,536,873 | 100% | ||
steemmillionaire | 0 | 24,695,355,043 | 100% | ||
lumendan | 0 | 584,752,923 | 100% | ||
humanabstract | 0 | 20,177,412,532 | 100% | ||
gregan | 0 | 6,515,110,538 | 100% | ||
chainstore | 0 | 142,145,313 | 100% | ||
h202 | 0 | 5,811,603,392 | 100% | ||
takry | 0 | 381,034,848 | 100% | ||
alexmaksto | 0 | 610,651,504 | 100% | ||
criticalkush | 0 | 2,583,383,213 | 100% | ||
magpielover | 0 | 129,699,957 | 100% | ||
itsragged | 0 | 314,300,170 | 100% | ||
c4h8n8o8 | 0 | 440,508,374 | 100% | ||
rcebike | 0 | 3,555,875,627 | 100% | ||
sau412 | 0 | 728,125,905 | 100% | ||
rishi-sayz | 0 | 308,766,207 | 100% | ||
steemprotector | 0 | 30,717,335,778 | 100% | ||
grwd | 0 | 2,014,146,179 | 100% | ||
steemgridcoin | 0 | 3,089,065,921 | 100% | ||
topgame | 0 | 29,838,865,357 | 100% | ||
nathanielcwm | 0 | 272,974,696 | 100% | ||
wave.beads | 0 | 307,322,043 | 100% | ||
chucklehead | 0 | 611,205,355 | 100% | ||
killereps | 0 | 7,500,453,822 | 100% | ||
verifyme | 0 | 75,524,865 | 10% | ||
aleolm | 0 | 552,051,987 | 100% |
What is use case for this?
author | sau412 |
---|---|
permlink | re-cm-steem-gridcoin-hug-rest-api-20180719t113459233z |
category | gridcoin |
json_metadata | {"tags":["gridcoin"],"app":"steemit/0.1"} |
created | 2018-07-19 11:35:00 |
last_update | 2018-07-19 11:35:00 |
depth | 1 |
children | 1 |
last_payout | 2018-07-26 11:35:00 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.273 HBD |
curator_payout_value | 0.088 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 26 |
author_reputation | 8,198,119,818,978 |
root_title | "Gridcoin HUG REST API" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 65,231,291 |
net_rshares | 171,935,037,466 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
cm-steem | 0 | 161,104,130,992 | 27% | ||
barton26 | 0 | 10,563,391,272 | 100% | ||
nathanielcwm | 0 | 267,515,202 | 100% |
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.
author | cm-steem |
---|---|
permlink | re-sau412-re-cm-steem-gridcoin-hug-rest-api-20180719t150218317z |
category | gridcoin |
json_metadata | {"tags":["gridcoin"],"links":["https://steemit.com/gridcoin/@cm-steem/boinc-user-xml-data-serialization-comparison"],"app":"steemit/0.1"} |
created | 2018-07-19 15:02:15 |
last_update | 2018-07-19 15:02:15 |
depth | 2 |
children | 0 |
last_payout | 2018-07-26 15:02:15 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.019 HBD |
curator_payout_value | 0.004 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 540 |
author_reputation | 58,522,774,254,119 |
root_title | "Gridcoin HUG REST API" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 65,253,448 |
net_rshares | 11,585,244,279 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
barton26 | 0 | 10,806,227,853 | 100% | ||
sau412 | 0 | 779,016,426 | 100% |
This is something I definitely want to look into, for some automation ideas on the Gridcoin blockchain. Thank you @cm-steem!
author | steemmillionaire |
---|---|
permlink | re-cm-steem-gridcoin-hug-rest-api-20180720t134616726z |
category | gridcoin |
json_metadata | {"tags":["gridcoin"],"users":["cm-steem"],"app":"steemit/0.1"} |
created | 2018-07-20 13:46:18 |
last_update | 2018-07-20 13:46:42 |
depth | 1 |
children | 0 |
last_payout | 2018-07-27 13:46:18 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.059 HBD |
curator_payout_value | 0.017 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 124 |
author_reputation | 127,790,992,179,371 |
root_title | "Gridcoin HUG REST API" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 65,367,095 |
net_rshares | 36,423,423,314 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
barton26 | 0 | 10,138,427,256 | 100% | ||
steemmillionaire | 0 | 25,541,211,531 | 100% | ||
sau412 | 0 | 743,784,527 | 100% |
@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.
author | verifyme |
---|---|
permlink | re-gridcoin-hug-rest-api-cm-steem-verifyme-randomvote |
category | gridcoin |
json_metadata | {"tags":["verifyme","random-upvote"],"users":["cm-steem","steemprotector"],"app":"null/null","format":"markdown"} |
created | 2018-07-19 23:28:09 |
last_update | 2018-07-19 23:28:09 |
depth | 1 |
children | 0 |
last_payout | 2018-07-26 23:28:09 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 217 |
author_reputation | -705,247,747,464 |
root_title | "Gridcoin HUG REST API" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 65,297,771 |
net_rshares | 0 |