# SDK integration

### SDK integration <a href="#sdk-integration" id="sdk-integration"></a>

{% hint style="info" %}
SDK a basic understanding of Javascript/Typescript and installed Web3.
{% endhint %}

You can easily install the SDK using the command:

```
// with npm
npm install bridgemuual

// or with yarn
yarn add bridgemutual
```

**Purchase policy**

```
import {_getWhitelistedContracts, getCoverageApprove, provideCoverage} from 'bridgemutual';

//returnts list of whitelisted contracts
param {Object} web3 - instance of web3
param {Boolean} isTest - for use Rinkeby TestNet
_getWhitelistedContracts(web3, isTest).then(policies => {
    //policies <== list of policies
})

//returns approved contract
param {Number} id - Id of policy
param {Object} web3 - instance of web3
param {Number} weeks - period of policy
param {Number} amount - amount of policy
param {String} userAddress - user address (in ETH)

getApprove(id, web3, weeks, amount, userAddress).then(approvedContract => {
    //approvedContract  <== list of policies
})

//returns policy price
param {String} userAddress - user address (in ETH)
param {Number} id - Id of policy
param {Number} amount - amount of policy
param {Number} weeks - period of policy
param {Object} web3 - instance of web3

getPolicyPrice(userAddress, id, amount, weeks, web3).then(policyPrice => {
    //policyPrice  <== policy price in USDT
})

//returns current allowance
param {Object} web3 - instance of web3
param {String} userAddress - user address (in ETH)
param {Number} id - Id of policy
param {Boolean} isTest - for use Rinkeby TestNet

getAllowance (web3, userAddress, id, isTest).then(currentAllowance => {
    //currentAllowance  <== current allowance
})

//returns current allowance
param {Object} web3 - instance of web3
param {String} userAddress - user address (in ETH)
param {Number} id - Id of policy
param {Boolean} isTest - for use Rinkeby TestNet

resetAllowance(web3, userAddress, id, isTest).then(currentAllowance => {
    //currentAllowance  <== current allowance equal 0
})

//returns current allowance
param {Object} web3 - instance of web3
param {String} userAddress - user address (in ETH)
param {Number} id - Id of policy
param {Number} policyPrice - from getPolicyPrice method 
param {Boolean} isTest - for use Rinkeby TestNet

setAllowance (web3, userAddress, id, policyPrice, isTest).then(currentAllowance => {
    //currentAllowance  <== current allowance
})

//returns policy purchase result
param {Number} id - Id of policy
param {Object} web3 - instance of web3
param {String} userAddress - user address (in ETH)
param {Number} weeks - period of policy
param {Number} amount - amount of policy
param {String} referralAddress - user address (in ETH)

buyPolicy(id, web3, userAddress, weeks, amount, referralAddress).then()
```

**Display purchased policies**

```
import {_getWhitelistedContracts, getCoverageApprove, provideCoverage} from 'bridgemutual';

//returnts list of whitelisted contracts
param {Object} web3 - instance of web3
param {Boolean} isTest - for use Rinkeby TestNet
_getWhitelistedContracts(web3, isTest).then(policies => {
    //policies <== list of policies
})

//returns list of purchased policies
param {Object} web3 - instance of web3
param {String} userAddress - user address (in ETH)
param {Boolean} active - active/unactive policies
param {Number} offset - offset
param {Number} limit - limit
param {Boolean} isTest - for use Rinkeby TestNet

getPurchasedPolicies (web3, userAddress, active, offset, limit, isTest).then(listPurchasedPolicies => {
    //listPurchasedPolicies  <== list purchased policies
})
```

**Earn Interest**

```
import {_getWhitelistedContracts, getCoverageApprove, provideCoverage} from 'bridgemutual';

//returnts list of whitelisted contracts
param {Object} web3 - instance of web3
param {Boolean} isTest - for use Rinkeby TestNet
_getWhitelistedContracts(web3, isTest).then(policies => {
    //policies <== list of policies
})

//returns current allowance
param {Object} web3 - instance of web3
param {String} userAddress - user address (in ETH)
param {Number} id - Id of policy
param {Boolean} isTest - for use Rinkeby TestNet

getAllowance (web3, userAddress, id, isTest).then(currentAllowance => {
    //currentAllowance  <== current allowance
})

//returns current allowance
param {Object} web3 - instance of web3
param {String} userAddress - user address (in ETH)
param {Number} id - Id of policy
param {Boolean} isTest - for use Rinkeby TestNet

resetAllowance(web3, userAddress, id, isTest).then(currentAllowance => {
    //currentAllowance  <== current allowance equal 0
})

//returns current allowance
param {Object} web3 - instance of web3
param {String} userAddress - user address (in ETH)
param {Number} id - Id of policy
param {Number} amount - amount of coverage
param {Boolean} isTest - for use Rinkeby TestNet

setAllowance (web3, userAddress, id, amount, isTest).then(currentAllowance => {
    //currentAllowance  <== current allowance
})

//returns coverage provided result
param {Number} id - Id of policy
param {String} userAddress - user address (in ETH)
param {Number} amount - amount of coverage

provideCoverage(id, userAddress, amount).then()
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dein-fi.gitbook.io/bridge-mutual/v2/bridge-mutual-widget/widget-integration/sdk-integration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
