How-To:Handle Withdrawals

From Nxt Wiki
Jump to: navigation, search
Other languages: English 100% • ‎español 100% • ‎français 100% • ‎italiano 100% • ‎Nederlands 20% • ‎português do Brasil 60% • ‎русский 100%

Developers have provided some insights into good methods for implementing features in your software. This tip was created by Come-from-Beyond.

For more information on the API calls referenced here, check our high-level API documentation.

One way to handle withdrawals

  1. Use this API call: http://localhost:7876/nxt?requestType=sendMoney&secretPhrase=123&recipient=2983475693816&amount=5000&fee=1&deadline=32767
  2. This request will return a transaction ID and transaction bytes.
  3. Save both these values and periodically check that transaction is still in the blockchain.
    • Due to possible transaction malleability issues, do not rely on transaction ID alone to verify a transaction has been sent.
  4. If the transaction becomes unknown or unconfirmed, you can rebroadcast it via broadcastTransaction (Transaction bytes can be obtained using getTransactionBytes)
  5. Once the transaction reaches 720 confirmations, it's safe.

Some very important things

  • If a claim is made that a transaction was not sent, do not use sendMoney again without making sure that the original transaction wasn't modified.
  • 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 http://localhost:7876/nxt?requestType=getTime
  • 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.
  • Until a transaction gets 720 confirmations you should check to be sure it's still confirmed. If not (due to blockchain reorg), rebroadcast the transaction it to the network using http://localhost:7876/nxt?requestType=broadcastTransaction&transactionBytes=f11234bd3a2fc19c2ba6b7c0d108deea9fcbafda5f544e4648c651ec4ed34ed2. Transaction bytes can be obtained via http://localhost:7876/nxt?requestType=getTransactionBytes&transaction=83492836836338756.