BTU.JS is a javascript library that interacts with BTU Protocol. It allows any developer to build a booking application or a widget.
- Getting started
- Components
- Resources methods
- searchResources
- getResource
- getResourceItem
- isRessourceAvailable
- addResource Private beta - contact us
- deleteResource Private beta - contact us
- editResource Private beta - contact us
- Availabilities methods
- searchAvailableResources
- getResourceAvailabilities
- bookResource
- getBookingDetails
- cancelBooking
- addAvailability Private beta - contact us
- removeAvailability Private beta - contact us
npm install btujs --save
const btujs = require('btujs');
const myBtujs = new btujs();
BTU Dappbar Technical documentation: The dappbar BTU is a tool for offer bringers to simplify cashback in BTU Token for their customers. In its current version (V2.1), the tool makes it possible to make the address of the wallet that is integrated in the user's browser available on the visited page in a uniform way. The dappbar use only requires HTML5, CSS3 and Javascript, (it is possible to integrate it on any JS framework: React, Angular etc ..). It allows to detect a wallet integrated to a Web3 compatible browser (Opera, plugins like Metamask, Dapp browsers like BTU-Direct, Trust, Coinbase etc ...)
-
Installation
-
Additional scripts First, the integration of the following scripts is necessary for the operation of the dappbar: ● JQuery (V3.4 or more) ● Web3 (1.0 or more) ● Dappbar.js (link updated)
If you have an html file, you can directly place the following HTML tags in the part of your file.
<script type="text/javacript"
src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/ethereum/[email protected]/dist/web3.min.js"> </script>
<script type="text/javascript"src="https://btu-cdn.s3.eu-west-3.amazonaws.com/public/dappbar.min.js"></script>
Otherwise you can insert the scripts by calling a JS functions.
const script = document.createElement('script')
script.src = 'https://cdn.jsdelivr.net/gh/ethereum/[email protected]/dist/web3.min.js'
script.async = true
document.head.appendChild(script)
Code to reproduce for each script previously mentioned.
- Place the dappbar
First of all, for the Dappbar.js script to be able to generate the dappbar, it
is necessary to decide on a place where it will be placed thanks to a </ div> tag with the specific "btu-placeholder" id. It is recommended to place it as early as possible in the code so that it takes up all the top space of the page.
<div id="btu-placeholder"></div>
- Use Once the dappbar has been installed, the user who visits the page will see his wallet connected automatically (or with an approbation request according to the system) to the dappbar. His information will be saved in the sessionStorage
● You can verify if the user is connected with the following call :
sessionStorage.getItem("BTU-walletConnected") // Return "false" or "true"
● You also can have acces to his wallet address by this call :
sessionStorage.getItem("BTU-walletAddr") // Return the BTU key (0xABF2...)
Finally, if your website is available in different domain names and you want to make the connexion possible to the wallet only in one of them (e.g. in the case you want the users who share the link of your website earns the cashback instead of the buyer, it is possible to specify the domain name(s) where you want the bar to appear. To add this content, please add a
"data-restrict-domain ="
attribute with the value(s) of the domain name(s).
<div id="btu-placeholder" data-restrict-domain=”test.com,test.fr”></div>
in the case this attribute is not specified, the dappbar is displayed by default without restrictions. The refund wallet address is to specify in the page URL, thanks to a parameter “w”, exemple : test.com?w=0xAB21...
Search for resources regardless of their availabilities.
myBtujs.resources.searchResources(String resourceType, Object body, Function callback)
Query resource by its ID to get its details.
myBtujs.resources.getResource(String resourceType, String resourceId, Object body, Function callback)
Query resource by its ID and its sub-item ID to get sub-item details.
myBtujs.resource.getResourceItem(String resourceType, String resourceId, String itemId, Object body, Function callback)
Search for availables resources only.
myBtujs.availabilities.searchAvailableResources(String resourceType, Object body, Function callback)
Query a resource by its ID and get its availabilities.
myBtujs.availabilities.getResourceAvailabilities(String resourceType, String resourceId, Object body, Function callback)
Check if a resource is available under different conditions.
myBtujs.availabilities.isResourceAvailable(String resourceType, String resourceId, Object body, Function callback)
{
isAvailable: true // or false
}
Book a resource availability.
myBtujs.availabilities.bookResource(String resourceType, String resourceId, Object body, Function callback)
Get informations about a booking you made.
myBtujs.availabilities.getBookingDetails(String resourceType, String bookingId, Object body, Function callback)
Cancel a reservation you booked through the bookResource method.
myBtujs.availabilities.cancelBooking(String resourceType, String bookingId, Object body, Function callback)