Purpose of this page is to both, propose a uniform API design which the libraries interfacing with IRI conform to, as well as act as a general guidance for library developers so that they better understand what needs to be implemented. Interoperability is key in making the lives of developers as easy as possible, as such, all libraries should stick to a commonly-agreed design. This will also make development and maintenance for core developers easier.
Join the Discussion
This is an early proposal, as such, public discourse is incredibly important in ensuring that the design is sound and will be adopted by developers. For discussions related to this proposal, and more importantly, if you want to engage in these discussions, I suggest you to join our Slack so that we can discuss the design.
In total there are 14 API calls which are available through IRI. You can get the full list from our API docs: https://iota.readme.io/.
To be added
This is a list of new API calls which will help do just about anything possible with IOTA. These are mostly wrapper functions, this means that there will be more functions required in achieving the results. We leave it open for the developers of the libraries to develop this extra functionality (the result should be universally the same obviously).
Gets all possible inputs of a seed and returns them with the total balance. This is either done deterministically (by genearating all addresses until findTransactions
is empty and doing getBalances), or by providing a key range to use for searching through.
getInputs(seed, [, options] [, callback])
seed
:String
tryte-encoded seed. It should be noted that this seed is not transferredoptions
:Object
which is optional:
start
:int
Starting key indexend
:int
Ending key indexthreshold
:int
Minimum threshold of accumulated balances from the inputs that is required
callback
:Function
Optional callback.
Object
- an object with the following keys:inputs
Array
- list of inputs objects consisting ofaddress
,balance
andkeyIndex
totalBalance
int
- aggregated balance of all inputs
Main purpose of this function is to get an array of transfer objects as input, and then prepare the transfer by generating the correct bundle, as well as choosing and signing the inputs if necessary (if it's a value transfer). The output of this function is an array of the raw transaction data (trytes).
An example implementation can be viewed here: https://github.com/domschiener/nostalgia/blob/master/js/iotajs.js#L535
prepareTransfers(seed, transfersArray [, options] [, callback])
seed
:String
tryte-encoded seed. It should be noted that this seed is not transferredtransfersArray
:Array
of transfer objects:
address
:String
81-tryte encoded address of recipientvalue
:Int
value to be transferred.message
:String
tryte-encoded message to be included in the bundle.tag
:String
27-tryte encoded tag.
options
:Object
which is optional:
inputs
:Array
List of inputs used for funding the transferaddress
:String
if defined, this address will be used for sending the remainder value (of the inputs) to.
callback
:Function
Optional callback.
Array
- an array that contains the trytes of the new bundle.
Generates a new address from a seed and returns the address. This is either done deterministically, or by providing the index of the new address (see Questions for more information about this).
getNewAddress(seed [, options] [, callback])
seed
:String
tryte-encoded seed. It should be noted that this seed is not transferredoptions
:Object
which is optional:
index
:Int
If the index is provided, the generation of the address is not deterministic.checksum
:Bool
Adds 9-tryte address checksumtotal
:Int
Total number of addresses to generate.returnAll
:Bool
If true, it returns all addresses which were deterministically generated (until findTransactions returns null)
callback
:Function
Optional callback.
String | Array
- returns either a string, or an array of strings.
This function returns the bundle which is associated with a transaction. Input can by any type of transaction (tail and non-tail). If there are multiple bundles (because of a replay for example), it will return multiple bundles. It also does important validation checking (signatures, sum, order) to ensure that the correct bundle is returned.
getBundle(transaction [, callback])
transaction
:String
Transaction hash, can be tail or non-tail. Tail search is more specific and leads to more exact results.callback
:Function
Optional callback
Array
- returns an array of arrays. Each array is a bundle, if there are multiple arrays it means that there are conflicting bundles.
Returns the transfers which are associated with a seed. The transfers are determined by either calculating deterministically which addresses were already used, or by providing a list of indexes to get the transfers from.
getTransfers(seed [, options] [, callback])
seed
:String
tryte-encoded seed. It should be noted that this seed is not transferredoptions
:Object
which is optional:
indexes
:Array
- optional. If the index of addresses is provided, it will be used to get all transfers associated with the addresses.inclusionStates
:Bool
If True, it gets the inclusion states of the transfers.
callback
:Function
Optional callback.
Array
- returns an array of transfers. Each array is a bundle for the entire transfer.
Takes a tail transaction hash as input, gets the bundle associated with the transaction and then replays the bundle by attaching it to the tangle.
replayTransfer(transaction [, callback])
transaction
:String
Transaction hash, has to be tail.callback
:Function
Optional callback
Array
- returns an array containing the replayed transactions (bundle).
Wrapper function that basically does prepareTransfers
, as well as attachToTangle
and finally, it broadcasts and stores the transactions locally.
sendTransfer(seed, depth, minWeightMagnitude, transfers [, options] [, callback])
seed
String
tryte-encoded seed. If provided, will be used for signing and picking inputs.depth
Int
depthminWeightMagnitude
Int
minWeightMagnitudetransfers
:Array
of transfer objects:
address
:String
81-tryte encoded address of recipientvalue
:Int
value to be transferred.message
:String
tryte-encoded message to be included in the bundle.tag
:String
27-tryte encoded tag.
options
:Object
which is optional:
inputs
:Array
List of inputs used for funding the transferaddress
:String
if defined, this address will be used for sending the remainder value (of the inputs) to.
callback
:Function
Optional callback.
Array
- returns an array of the transfer (transaction objects).
Wrapper function that does attachToTangle
and finally, it broadcasts and stores the transactions locally.
sendTrytes(trytes, depth, minWeightMagnitude, [, callback])
trytes
Array
trytesdepth
Int
depthminWeightMagnitude
Int
minWeightMagnitudecallback
:Function
Optional callback.
Array
- returns an array of the transfer (transaction objects).
Wrapper function that does broadcastTransactions
and storeTransactions
broadcastAndStore(trytes [, callback])
trytes
Array
trytescallback
:Function
Optional callback.
Array
- returns an array of the transfer (transaction objects).
These are proposed utility functions.
Takes an 81-trytes address as input and calculates the 9-trytes checksum of the address.
addChecksum(address)
address
String
81-trytes address
String
- returns 90-trytes address (81-trytes address + 9-trytes checksum)
Removes the 9-trytes checksum of the address.
removeChecksum(address)
address
String
90-trytes address
String
- returns 81-trytes address
Takes 90-trytes address with checksum as input, generates the checksum and compares the result.
isValidChecksum(addressWithChecksum)
addressWithChecksum
String
90-trytes address
Bool
- True/False if addressWithChecksum is valid or not.
Converts a unit to another. Units are from the standard system of units (here is a unitMap: https://github.com/iotaledger/iota.lib.js/blob/master/lib/utils/utils.js#L9)
convertUnits(value, fromUnit, toUnit)
value
Int
value to convertfromUnit
String
current unit of the valuetoUnit
String
unit to convert to
Int
- returns the new converted value.
Converts transaction trytes into a transaction object so that the values of the transaction can be easily read.
transactionObject(trytes)
trytes
Array
- array of transaction trytes
Array
- array of transaction objects
Converts transaction objects into trytes.
transactionTrytes(transactionObjects)
transactionObjects
Array
- array of transaction objects
Array
- array of transaction trytes
Takes a transaction bundle as input and correctly reads the associated message that was sent. In some cases when the message exceeds the 2187-trytes limit per transaction, this function might be really useful in correctly outputting the full message value.
readMessage(transactionBundle)
transactionBundle
Array
- array of transaction bundle
String
- message which was sent with the transfer
Converts a string into trytes according to a standardized conversion schema. Works for either ASCII and UTF-8.
toTrytes(string, encoding)
string
String
encoding
String
- either ASCII or UTF-8
String
- trytes
Converts a trytes into a string according to a standardized conversion schema. Works for either ASCII and UTF-8.
toString(trytes, encoding)
trytes
String
encoding
String
- either ASCII or UTF-8
String
- string
Validator object which contains functions for the validation of certain inputs.
Bool
- True/False
- For
prepareTransfers
, should the user be able to define the remainder address? - For
prepareTransfers
, should the user be able to define the inputs? (A problem is that the users of the libraries need to keep track of indexes of addresses.) - For
getTransfers
, should we make it possible to define the indexes for addresses?