Automate Nxt for your website
For creating and testing your automated system you can take advantage of Testnet server*=http://holms.cloudapp.net:6874 before you publish it to public net server*=http://localhost:7874. To get testNxt simply post your testNet address on the main forum, devs who is constantly testing features will send you some.
a) Generate account and deposit funds
combine “Master secretPhrase” + “User secretPhrase” and create Nxt account for that user.
For example: you can use a userID/email/something unique for each user plus master secretphrase.
or use "Master secretPhrase"+ID to generate a passphrase for the deposit
account. example "secret8475347836".
server*/nxt?requestType=getAccountId&secretPhrase=secret8475347836
will return the corresponding account id. You should give this ID to the user.
{"accountId":"6975576163363041725"}
server*/nxt?requestType=getAccountPublicKey&account=6975576163363041725
if account exist but no outgoing transactions or exist with outgoing/withdraw transactions, query returns
{} or {"publicKey":"5aa041670bc0b45c283c988b7f2f17735209cbabde5d5ce8a849b0d63a3a4422"}
If the account does not yet exist, this call should return error code 5, "unknown account", in a JSON object.
{"errorCode":5,"errorDescription":"Unknown account"}
server*/nxt?requestType=getAccountTransactionIds&account=6975576163363041725×tamp=0
timestamp=0 - returns get all transactions
{"transactionIds":["3988685842404561744","17488654975990478062"]}
transactions are ordered as 1st one is the oldest/first transaction, last one is the latest.
{"sender":"17102884928221738157","fee":1,"amount":33,"timestamp":7631107,"referencedTransaction":"0","confirmations":16,"subtype":0,"block":"7703346099660857010","senderPublicKey":"7e0ba6e8c6e1970dd975db46c9f5213f0540f3b35b2db550addaa8ec00b7c42d","type":0,"deadline":1440,"signature":"23d0b8078c711fd2f6c2d330756227e4df7554dd89d8c117d53453232659b8065a4d8c7b912c0aaf869074da26ba562ed421e56dc1392fd50d5433af2bdeb363","recipient":"6975576163363041725"}
Next time when user deposit fund again you can easily find latest transaction by comparing with your
note.
b) One way to handle withdrawals
{"bytes":"00001d067500a0055aa041670bc0b45c283c988b7f2f17735209cbabde5d5ce8a849b0d63a3a4422adf4092d3aa759ed1900000001000000000000000000000063ea4a68f8236c47c9295940169e4d1c38c85ce58d049b2366d60ad576d0060960b5beef69ea7e8b026eafe97a0e4bb1cb14451d70548b83fde57e4bb8a0ed2e","transaction":"5403653505501629715"}
server*/nxt?requestType=getTransaction&transaction=5403653505501629715
{"sender":"6975576163363041725","fee":1,"amount":25,"timestamp":7669277,"referencedTransaction":"0","confirmations":1,"subtype":0,"block":"12436520320458314283","senderPublicKey":"5aa041670bc0b45c283c988b7f2f17735209cbabde5d5ce8a849b0d63a3a4422","type":0,"deadline":1440,"signature":"63ea4a68f8236c47c9295940169e4d1c38c85ce58d049b2366d60ad576d0060960b5beef69ea7e8b026eafe97a0e4bb1cb14451d70548b83fde57e4bb8a0ed2e","recipient":"17102884928221738157"}
server*/nxt?requestType=getTransactionBytes&transaction=5403653505501629715
{"bytes":"00001d067500a0055aa041670bc0b45c283c988b7f2f17735209cbabde5d5ce8a849b0d63a3a4422adf4092d3aa759ed1900000001000000000000000000000063ea4a68f8236c47c9295940169e4d1c38c85ce58d049b2366d60ad576d0060960b5beef69ea7e8b026eafe97a0e4bb1cb14451d70548b83fde57e4bb8a0ed2e","confirmations":7}
{"transaction":"5403653505501629715"}
Some very important notes
Blocks can become orphaned and transactions can be cancelled, so pay attention to the timestamp and deadline values of a transaction.
Timestamp is measured in seconds since the genesis block (24th of Nov, 2013 12:00:00 UTC).
The transaction deadline is measured in minutes.
A transaction expires when timestamp + deadline * 60 < current time.
It can't be included into a block with a timestamp greater than timestamp (of the transaction) + deadline * 60. The current time can be obtained with
server*/nxt?requestType=getTime
{"time":7670086}
To make sure that you won't lose the transaction you should check that a user uses large deadline and doesn't try to cheat you by setting a timestamp too far in the past.
Also, until a transaction gets 720 confirmations you should check it's still confirmed. If not (due to blockchain reorg), rebroadcast the transaction as in section b.4.
Note, it is important to test your automation in public net, after you done testing it on testnet.
More API documentation can be found at: http://wiki.nxtcrypto.org/wiki/Nxt_API
Check How to guides at: http://wiki.nxtcrypto.org/wiki/How-To