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:Stringtryte-encoded seed. It should be noted that this seed is not transferredoptions:Objectwhich is optional:
start:intStarting key indexend:intEnding key indexthreshold:intMinimum threshold of accumulated balances from the inputs that is required
callback:FunctionOptional callback.
Object- an object with the following keys:inputsArray- list of inputs objects consisting ofaddress,balanceandkeyIndextotalBalanceint- 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:Stringtryte-encoded seed. It should be noted that this seed is not transferredtransfersArray:Arrayof transfer objects:
address:String81-tryte encoded address of recipientvalue:Intvalue to be transferred.message:Stringtryte-encoded message to be included in the bundle.tag:String27-tryte encoded tag.
options:Objectwhich is optional:
inputs:ArrayList of inputs used for funding the transferaddress:Stringif defined, this address will be used for sending the remainder value (of the inputs) to.
callback:FunctionOptional 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:Stringtryte-encoded seed. It should be noted that this seed is not transferredoptions:Objectwhich is optional:
index:IntIf the index is provided, the generation of the address is not deterministic.checksum:BoolAdds 9-tryte address checksumtotal:IntTotal number of addresses to generate.returnAll:BoolIf true, it returns all addresses which were deterministically generated (until findTransactions returns null)
callback:FunctionOptional 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:StringTransaction hash, can be tail or non-tail. Tail search is more specific and leads to more exact results.callback:FunctionOptional 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:Stringtryte-encoded seed. It should be noted that this seed is not transferredoptions:Objectwhich 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:BoolIf True, it gets the inclusion states of the transfers.
callback:FunctionOptional 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:StringTransaction hash, has to be tail.callback:FunctionOptional 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])
seedStringtryte-encoded seed. If provided, will be used for signing and picking inputs.depthIntdepthminWeightMagnitudeIntminWeightMagnitudetransfers:Arrayof transfer objects:
address:String81-tryte encoded address of recipientvalue:Intvalue to be transferred.message:Stringtryte-encoded message to be included in the bundle.tag:String27-tryte encoded tag.
options:Objectwhich is optional:
inputs:ArrayList of inputs used for funding the transferaddress:Stringif defined, this address will be used for sending the remainder value (of the inputs) to.
callback:FunctionOptional 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])
trytesArraytrytesdepthIntdepthminWeightMagnitudeIntminWeightMagnitudecallback:FunctionOptional callback.
Array - returns an array of the transfer (transaction objects).
Wrapper function that does broadcastTransactions and storeTransactions
broadcastAndStore(trytes [, callback])
trytesArraytrytescallback:FunctionOptional 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)
addressString81-trytes address
String - returns 90-trytes address (81-trytes address + 9-trytes checksum)
Removes the 9-trytes checksum of the address.
removeChecksum(address)
addressString90-trytes address
String - returns 81-trytes address
Takes 90-trytes address with checksum as input, generates the checksum and compares the result.
isValidChecksum(addressWithChecksum)
addressWithChecksumString90-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)
valueIntvalue to convertfromUnitStringcurrent unit of the valuetoUnitStringunit 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)
trytesArray- array of transaction trytes
Array - array of transaction objects
Converts transaction objects into trytes.
transactionTrytes(transactionObjects)
transactionObjectsArray- 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)
transactionBundleArray- 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)
stringStringencodingString- 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)
trytesStringencodingString- 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?