rooot-browser-lib
v0.20.0
Published
Browser library for the rooot project
Downloads
7
Readme
rooot-browser-lib
This library holds the common modules used by the Rooot™ system in TypeScript. It's specially suited for websites interacting with the blockchain.
Usage
npm i rooot-browser-lib
NB: The library is still under development, so ask us for installation guidelines.
Examples
import {
AccountsRestClient, GatewayRestClient, MetadataRestClient, TermsRestClient, TransactionRestClient,
buildOblivionTransaction, createOblivionTransaction, Vectors
} from 'rooot-browser-lib'
// Get all account information
const accountsRestClient = AccountsRestClient('http://localhost:3014')
accountsRestClient.getAccount(yourCredentials).then(account => {
// Use its info, eg. list its vectors
console.log(Vectors(account.vectors).list())
})
// Ask for the metadata
const metadataRestClient = MetadataRestClient('http://localhost:3013')
metadataRestClient.getMetadata().then(metadata => {
// Use them
console.log(metadata.lastBlockId, metadata.timestamp)
})
// Get a transaction from a depositary's gateway
const gatewayRestClient = GatewayRestClient('http://localhost:3030')
gatewayRestClient.getTransaction('1234567890abcdef[...]')
.then(transaction => {
// Do sth with it
console.log(transaction)
})
.catch(err => {
// Handle it
console.error(err)
})
// Know the latest terms of a smart contract
const termsRestClient = TermsRestClient('http://localhost:3004')
termsRestClient.getTerms(publicKey)
.then(terms => {
// Read them
console.log(terms.status, terms.channel, terms.end, terms.maxUse)
})
// Post an oblivion transaction
const transactionRestClient = TransactionRestClient('http://localhost:3003')
const oblivionTx = await transactionRestClient.getMetadata()
.then(([metadata, beneficiary]) => buildBaseOblivion(optinTx, optoutTx.transactionId, metadata, emitter, beneficiary)
.then(createOblivionTransaction)
)
transactionRestClient.sendOblivion(oblivionTx)
// Get the IDs of the 10 last blocks
const gatewayRestClient = GatewayRestClient('http://localhost:3030')
gatewayRestClient.last10Blocks()
.then(blockIds => {
// Do sth with them
console.log(blockIds.includes(transaction.lastBlockId))
})
Dependencies
To run the tests, you would need to install live-server
:
npm i -g live-server
License
The use of the Rooot™ libraries and executables are subject to fees for commercial purpose and to the respect of the BSD-2-Clause-Patent license. Please contact us to get further information.