Nxt Discussion > Nxt Projects

NXT PHP Client Library


Here is my PHP client library for NXT on Github.

I use it in my projects, I extend the CNxtApi class which contains the basics to query the NXT API to devellop more specific function. I cleaned it such it is always a good base to start with.

Making a request to your node in PHP then goes like this:

--- Code: ---$oApp = new CNxt;
$oApp->aInput = array(
                'message'=>'Here is your payment',
$oResp = $oApp->getResponse();

--- End code ---

It also comes with a class and bootstrap script to make a command line tool (on linux only after seting up an alias in .bash_aliases) that simplify updates, network checking and some api queries.
It can also serves as a good example on how to play with NXT and PHP.

Here is the output for

--- Quote ---nxt help
--- End quote ---

--- Quote ---USE: nxt {commands} (optional: -json, -ssh)


The command line utility can be used for any NXT API Request,
{command} is equivalent to the http query string of the API but
value pair are separted by *space* instead of *&*

Examples :

nxt requestType=getBlockchainTransactions account=NXT-THLJ-CYAL-JQST-6FNS5

OPTIONAL parameters

 (default) - returns the CURL request and readable output of objects (good to be used on the command line)
 -json : only returns the json string (good to be used by programs).
 -ssh : a usefull workaround for nodes that do not have https set up, the distant node must have this library installed.
        Then the node is queried via ssh and then makes it's final request to the NXT server with with http://localhost:7876


Below are custom commands that are defined in commands/boostrap
The options -json and -ssh described above are also available

nxt getBalance NXT-39LJ-V67N-TJB9-EHUKA -json
-- NODE OPERATION on LOCAL MACINE --------------------------------

nxt version               : Retuns version of the server
nxt update 1.10.3            : Update to the version given - Manual confirmation required after download completed and sha256sum of the zip is outputed.
nxt start                : Starts the local NXT server
nxt stop                : Kill NXT server process
nxt restart               : Stop then Start
nxt unlock                : Start forging interactive screen asks for passphrase
nxt lock                : Stop forging, interactive screen asks for passphrase
nxt stay_alive               : Restart server if it is not runing
nxt stay_alive forge            : Restart server if it is not runing + alert admin that forging has stopped (if it did..)
nxt backup               : Creates a backup of H2 database (blockchain) with minimum downtime (speed up recovery if DB files get corrupted.. which still happens sometimes)

-- NETWORK INFORMATIONS -----------------------------------------

nxt getconfig               : Get the config parameters
nxt getState               : Get blockchain state of the NODE in config
nxt network               : Gives data about nodes that you survey
                  - defines the nodes in private-config.php with php array, example:
                     $aWhiteListeNodes['nxt'] = array('','http://nxt.scriba.io:7876')

-- ENCODING DECODING -----------------------------

nxt getToken www.notbot.me         : create token, interactive screen asks for passphrase
nxt decodeToken www.notbot.me sbfmg...88jh   : decode token sbfmg12288jh
nxt decodeHallmark shall65s4fps         : decode hallmark shall65s4fps

-- ACCOUNTS --------------------------------------

nxt getBalance NXT-39LJ-V67N-TJB9-EHUKA    : get balance of NXT-39LJ-V67N-TJB9-EHUKA (accept also the numerical account format)
nxt getAccountId             : return accountId, interactive screen asks for passphrase
nxt getAccountId 9fdg87hf9d8g7h9d8f7gh9      : return accountId for passphase 9fdg87hf9d8g7h9d8f7gh9
nxt getAccount NXT-39LJ-V67N-TJB9-EHUKA    : get a bunch of informations about account (accept also the numerical account format)
nxt getAliases  NXT-39LJ-V67N-TJB9-EHUKA    : get all the aliases owned by an account (accept also the numerical account format)
nxt getAlias scriba             : get the informations about the alias "scriba"

-- ENCODING DECODING -----------------------------
== BLOCK ==

nxt getBlock 17643352830869739755       : return block data

-- ENCODING DECODING -----------------------------

nxt getPeers                : return peers of the node

- Options
nxt getPeers active
nxt getPeers connected
nxt getPeers disconnected
nxt getPeers non_connected
nxt getPeers API
nxt getPeers API_SSL
nxt getPeers hallmark
nxt getPeers prunable

-- HELP ------------------------------------------

nxt help                : return this help

-- FUN -------------------------------------------

nxt mine whateverpassphrase          : return accountId and Balance if you are luck enouh !

--- End quote ---

I hope it will be usefull to you.

Added to https://nxtforum.org/general-discussion/100-blockchain-related-apps/

Proud to be on that list!
I just discovered the Javascript NXTDevKit I think it's going to help me.
Communication matters !  :)

Project alive ?


--- Quote from: jonnytracker on May 11, 2018, 06:44:41 pm ---Project alive ?

--- End quote ---
It is not a living creature you know.. but "yes" Github link is up to date.


[0] Message Index

Go to full version