Nxt Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest Nxt Client 1.11.9 - NEW RELEASE: Ardor 2.0.3e TestNet IS LAUNCHED!

Pages: [1]

Author Topic: NXT PHP Client Library  (Read 717 times)

websioux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 306
  • Great changes grow bottom up
    • View Profile
    • Scriba.io the Blockchain Scribe
  • Karma: +67/-1
NXT PHP Client Library
December 16, 2016, 12:00:50 pm

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: [Select]
$oApp = new CNxt;
$oApp->aInput = array(
                'requestType'=>'sendMoney',
                'recipient'=>'NXT-SL44-R65Z-HMNZ-7WVJM',
                'amountNQT'=>'500000000000',
                'secretPhrase'=>'PUT_YOUR_HOT_WALLET_SECRET',
                'message'=>'Here is your payment',
                'messageIsPrunable'=>true,
                'messageToEncrypt'=>true,
                'feeNQT'=>100000000             
);
$oResp = $oApp->getResponse();

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

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

**************************************************
   GENERAL API
**************************************************

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

**************************************************
   COMMAND LINE SHORTCUTS
**************************************************

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

Example:
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://127.0.0.1:7876','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 -----------------------------
== NETWORK ==

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 !

I hope it will be usefull to you.


Secret Miner <= communicate with style | NotBot <= timestamp digital docs

lurker10

  • Hero Member
  • *****
  • Offline Offline
  • Posts: 1336
    • View Profile
  • Karma: +168/-33
Run a node - win a prize! "Lucky node" project jar: NXT-8F28-EDVE-LPPX-HY4E7

websioux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 306
  • Great changes grow bottom up
    • View Profile
    • Scriba.io the Blockchain Scribe
  • Karma: +67/-1
Re: NXT PHP Client Library
December 16, 2016, 12:53:35 pm

Proud to be on that list!
I just discovered the Javascript NXTDevKit I think it's going to help me.
Communication matters !  :)
Secret Miner <= communicate with style | NotBot <= timestamp digital docs
Pages: [1]