The NKN open API is a blockchain-to-database parser with an easy to use interface written in PHP. We're using Laravel as our framework to provide a clean and maintainable code.
This API gives you all the handy features you need to code your app such as:
- History queries of all ever created blocks
- Already parsed and human readable payloads
- A websocket interface to pub/sub to latest block updates
- and many more
You can also host NKN open API by yourself!
If you want to jump right into app developing it's a good idea to check out our documentation. All api endpoints are already documented here.
Missing a feature? Just create an Issue for that and we'll implement it!
If you want to host your own NKN API by yourself you at least need
- Composer installed
- A configured web server (Nginx or Apache) with minimal: -- 2 CPU cores -- 4 Gigabytes of RAM -- 50 Gigabytes of Storage
- At least PHP 7.2.5 -- redis extension
- PostgreSQL database server
- A Redis database for queues
If you're not that much into setting your system up you can always use a virtual machine with Laravel Homestead if you're on Windows/Linux or Laravel Valet when you're on a Mac.
Run composer install
to install all dependencies
Create a file called .env
with the basic variables (Change them to your needs):
APP_NAME="NKN Open API"
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=YOUR_URL_HERE
LOG_CHANNEL=stack
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=PGSQL_DB_NAME
DB_USERNAME=PGSQL_USER_NAME
DB_PASSWORD=PGSQL_USER_PASSWORD
BROADCAST_DRIVER=pusher
CACHE_DRIVER=redis
QUEUE_CONNECTION=redis
SESSION_DRIVER=file
SESSION_LIFETIME=120
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=REDIS_PASSWORD
REDIS_PORT=6379
PUSHER_APP_ID=RANDOM_APP_ID
PUSHER_APP_KEY=RANDOM_APP_KEY
PUSHER_APP_SECRET=RANDOM_APP_SECRET
PUSHER_APP_CLUSTER="mt1"
UPDATEINTERVAL = 20
REMOTENODE_ADDR = PUBLIC_NODE_ADDR (f.e. 'https://mainnet-rpc-node-0001.nkn.org/mainnet/api/wallet', better results with a local node)
REMOTENODE_PORT = 30003
You can also just rename .env.example
to get the configurations of the public available API.
php artisan key:generate
php artisan migrate
php artisan horizon
php artisan websockets:serve
php artisan blockchain:init
Note: If you got a minimal specs server redis will run out of memory after more than 400k jobs. To avoid this we recommend to cancel out the job if your queue reaches >300k blocks. Let all jobs run and then rerun the command for the next 300k blocks.
You can check your redis queue by pointing your browser at http://YOUR_IP/horizon
.
You got two options for this:
- run
php artisan balances:sync
once to push all address-updates to the queue. Again: this is only doable with a performant server. - Head over to
app/Console/Kernel.php
uncomment the following line to update 2000 Addresses every 5 minutes:// $schedule->command('balances:sync --limit 2000')->everyFiveMinutes();
Setup an "every minute" job that runs php artisan schedule:run
to get regular updates in time. Also don't forget to set APP_ENV=production
in your .env
file.
Wow! That is very nice of you! The contribution guide will come shortly. Meanwhile join us on the official NKN Discord channel and let us know your thoughts.
The NKN open API is open-sourced software licensed under the MIT license.