This thread is dedicated to discussion of Nxt API. Information about Nxt can be found at https://bitcointalksearch.org/topic/ann-nxt-descendant-of-bitcoin-303898Requests to Nxt software are done using HTTP GET requests. Parameters are passed as HTTP parameters. Responses are returned as JSON objects. If something goes wrong a response will look
{"errorCode": 6, "errorDescription": "Blah-blah-blah"}.
The list of all requests is below, I will update it each time I add new ones.
Decode tokenDecodes an authorization token.
Request:http://localhost:7876/? request=decodeToken & website=www.domain.com & token=StringOf160Chars
Response:{ "account": "398532577100249608", "timestamp": 622, "valid": true }
Note:This approach should be used to authorize users on web sites.
Get balanceRetrieves the balance of an account.
Request:http://localhost:7876/? request=getBalance & account=398532577100249608
Response:{ "balance": 5000, "unconfirmedBalance": 4200 }
Note:"unconfirmedBalance" is the balance minus all unconfirmed sent transactions. It doesn't include double-spending and unconfirmed received transactions. A user sees the unconfirmed balance in the client.
Get blockRetrieves block data.
Request:http://localhost:7876/? request=getBlock & block=12726165958299924733
Response:{ "height": 16, "generator": "398532577100249608", "timestamp": 504, "numberOfTransactions": 149, "totalAmount": 17400, "totalFee": 24, "version": 1, "baseTarget": "54029906605928", "previousBlock": "3483738553242041290", "nextBlock": "9200836476619146595", "payloadHash": "32BytesRepresentedInHexadecimalForm", "generationSignature": "64BytesRepresentedInHexadecimalForm", "blockSignature": "64BytesRepresentedInHexadecimalForm", "transactions": ["2590525739676698091", "5436057910978689871", "8815617645011985536", ...] }
Note:"generator" is the account that generated the block.
Payload length = "numberOfTransactions" * 128 B.
"previousBlock" absents for the genesis block.
"nextBlock" absents for the last block in the blockchain.
"transactions" is an array of transaction ids.
Get timeRetrieves current time.
Request:http://localhost:7876/? request=getTime
Response:{ "time": 417 }
Note:"time" is measured in seconds since the genesis block timestamp.
Get transactionRetrieves transaction data.
Request:http://localhost:7876/? request=getTransaction & transaction=16244659048134841060
Response:{ "block": "12726165958299924733", "timestamp": 417, "deadline": 900, "sender": "6330031667105067575", "recipient": "398532577100249608", "amount": 1500, "fee": 5, "confirmations": 2, "signature": "64BytesRepresentedInHexadecimalForm" }
Note:Data of an unconfirmed transaction doesn't contain "block" and "confirmations" parameters. Double-spending transactions are not retrieved.
Send moneySends money.
Request:http://localhost:7876/? request=sendMoney & secretPhrase=IWontTellYou & recipient=398532577100249608 & amount=1500 & fee=5 & deadline=900 & referencedTransaction=13689168149259791567
Response:{ "transaction": "16244659048134841060" }
Note:"deadline" is specified in minutes.
"referencedTransaction" can be omitted.