5 things to know when building on IOTA
The full article was originally published by Phani on Medium. Read the full article here.
Here are a few lessons learned while working on IOTA for the past 4 months.
1. Attaching addresses to Tangle
A new address can be generated using getNewAddress API method. The libraries/API do not attach the address to the Tangle automatically for you. You can always successfully send IOTAs to non-attached addresses but it is recommended to attach an address before using it.
You can attach it by sending a zero-value transaction.
Wait a minute! Then what would be the source address?
Good question, in IOTA, a zero-value transaction bundle does not have (or need) a source address. So, your source address will be the destination address you want to attach.
Also, there can be few caveats with optional parameter assumption. The optional parameter is not an empty string but an equivalent null. Below is a simple prepareTransfers method:
List <String> trytes = jiota.prepareTransfers(seed, security, transfers, remainderAddress, inputs, tips, validateInputs);
Here remainderAddress is an optional param. When
String remainderAddress = "";
remainderAddress is an empty string, it would work fine for 0 value transactions but would fail for any > 0i value transactions. The correct way to make it optional is setting to null.
String remainderAddress = null;
3. Promoting vs Reattaching
When the transaction is pending for a long time, it is unlikely to be accepted because the tip selection algorithm favors newer transactions. Users that are in a hurry to see their transaction confirmed are thus likely to rebroadcast it.
Rebroadcasting can be done by “promote” or “reattaching”. In practice “promoting”, which involves the creation of a zero value transaction, appears to be more effective.
The difference is promoting will create a zero value transaction and is now the top of Tangle and is more likely to get confirmed by other transactions, whereas, reattaching we create a new transaction with the same signed bundle as the original.
Not all transactions can be promoted. In IOTA.js, there is a handy method isPromotable that tells you if a tail transaction can be promoted or not.