Constructing the Transaction Object
There are several ways to construct a
Transaction instance. We recommend
using the transaction factory that is on the umbrella Zilliqa object, like
Signing the Transaction
Again, there are a few ways you can sign your transaction. Under the hood,
signing is done with the elliptic curve
secp256k1. The easiest way to do
this is by using a wallet. Extending our example above:
Note that we provided the nonce to use when constructing the transaction. If the nonce is not provided, zilliqa-js will automatically try to determine the correct nonce to use. However, if there is no network connection, zilliqa-js will not be able to do that, and signing will fail.
Transaction is successfully signed, you will be able to access the
signature property on
At this stage, you'll be able to broadcast your newly-signed transaction to the network through a seed node.
Sending the Transaction
Broadcasting a signed transaction is trivial, but involves some subtleties that can trip you up if you do not have a deep understanding of Zilliqa's architecture.
We demonstrate a lower-level way to broadcast a transaction using the built-in
HTTPProvider, as follows:
This returns a
Promise that, if successful, will contain your transaction
However, note that
result will not exist on the response if there is an
error in processing the transaction. Instead, the response will contain an
error key, which is an object that complies with JSON-RPC 2.0.
If you receive a
TranID, that means your transaction was accepted by the
seed node, and is now pending.
zilliqa-js provides a way to automatically
poll the lookup for confirmation:
confirm method returns a Promise the status of which signifies the
confirmation status of the transaction. If the transaction was confirmed: