Tangleview Client Library for JavaScript
Add following scripts to the bottom of your <body>
tag or to the equivalent place you integrate them in your project.
<script src="js/lokijs.min.js" type="text/javascript"></script>
<script src="js/socket.io.min.js" type="text/javascript"></script>
<script src="js/tangleview.min.js" type="text/javascript"></script>
Note: The order is important!
lokijs.min.js
andsocket.io.min.js
need to be called beforetangleview.min.js
To implement tangleview into your project, add following line:
const tangle = new tangleview({ host: 'localhost', ssl: false });
Options
host
The URL of your tangleview
instance. If not specified, it will use the URL of the browser.
ssl
If you have secure ssl enabled adapt this setting (calls https://
instead of http://
).
Note: If you have tangleview installed on the URL which is used by your project, you can leave the options empty
{}
. If will automatically call the API according to the called URL of the browser.
Following calls and hooks to the tangleview
instance are currently available:
Returns Promise
/ Array
of TX objects
tangle
.getTxHistory({ amount: 15000 })
.then(history => {
console.log('Tangle history:', history);
})
.catch(err => {
console.log('Error fetching Tangle history:', err);
});
Removes TX from the Tangle state.
query
can be like any MongoDB query scheme. (eg. { value: { $ne: 0 } }
equals all value TX or {}
equals all TX).
queryOptions
only supports limit
for now. It restricts the amount of TX to delete, starting from the most recent one.
For example, remove({}, {limit: 50})
deletes any of the last 50 TX.
remove()
triggers on('tangleStateChanged')
and on('tangleStateRemoved')
tangle.remove(
{ value: { $ne: 0 } },
{
limit: 50
}
);
Returns object
of newly propagated TX.
tangle.on('txNew', newTxObject => {
console.log('New TX on Tangle:', newTxObject);
});
Returns object
of newly discovered confirmation.
tangle.on('txConfirmed', newTxConfirmationObject => {
console.log('New confirmation on Tangle:', newTxConfirmationObject);
});
Returns object
of newly discovered reattachment.
tangle.on('txReattaches', newTxReattachmentObject => {
console.log('New reattachment on Tangle:', newTxReattachmentObject);
});
Returns list
of TX of current Tangle state. Gets triggered if an app modifies the Tangle state within the library.
tangle.on('tangleStateChanged', newTangleState => {
console.log('State of Tangle has changed, updated version:', newTangleState);
});
Returns list
of TX which have been deleted. Gets triggered if an app deleted TX from the Tangle state within the library.
tangle.on('tangleStateRemoved', removedTx => {
console.log('List of removed TX:', removedTx);
});
Returns object
of newly discovered milestone.
tangle.on('milestones', newMilestoneObject => {
console.log('New milestone on Tangle:', newMilestoneObject);
});