APIs for service integration
How to request for the services provided by InsurAce.io
InsurAce.io APIs currently supports the following services:
  • Get $INSUR token information
  • Retrieve product information
  • Buy cover
More APIs will be added soon.
The APIs are documented using Swagger. For details, please check:
⚠️ Note: Some APIs may require a code to access, please contact our technical team via Telegram, Discord, Forum or email to [email protected] to get the access code.

Find below a quick guide on how to use the various APIs for different service requests:

Get $INSUR token information

To get the total and circulating supply of $INSUR, you can call these APIs:
getCirculation : get the sum of INSUR in circulation on different networks
getTotalAmount : get the sum of all INSUR on different networks

Retrieve product information

To retrieve product information such as premium, capacity, protocol name and etc., please contact our technical team via Telegram, Discord, Forum or email to [email protected] to get the access code first.
Once done, you can call these APIs:
getProductList : Return a list of all products covered with details such as product id, name, capacity, annual premium and etc.
getCurrencyList : Return a list of tokens that can be used to purchase the cover with details such as token name, contract address and etc.

Buy cover

The full sample code for buying cover using JS code can be found here
You can follow the instruction there to run the test code.
Below is a step-by-step illustration of the JS code:

Step 1: Configuration

Prior to calling the APIs, you need to configure the following parameters first, here is a sample code:
1
//---------------------------------------
2
// Configuration
3
//---------------------------------------
4
5
// The JSON RPC URL that connects to an Ethereum node.
6
const jsonRpcUrl = '';
7
8
// The private key of a wallet that is used to purchase this cover.
9
const privateKey = '';
10
11
// The address of InsurAce Cover contract, ask InsurAce team to get address
12
// different chain has different addresses.
13
const contractAddress = 'xxxx';
14
15
// The URL of InsurAce API.
16
const httpApiUrl = 'https://api.insurace.io/ops/v1';
17
18
// The code that allows consumers to access InsurAce API.
19
const httpApiCode = '';
20
21
// The blockchain that the cover purchase transaction is sent to.
22
// Valid values are ETH, BSC or Polygon.
23
const chain = 'ETH';
24
25
// The product IDs for this cover purchase. Can be more than 1 product IDs.
26
// To get the product ID, please check https://api.insurace.io/docs or
27
// https://docs.insurace.io/landing-page/documentation/protocol-design/product-design/product-list
28
const productIds = [1, 2];
29
30
// The cover period (in days) for each product.
31
const coverDays = [30, 365];
32
33
// The cover amount for each product.
34
const coverAmounts = [utils.parseEther('1000'), utils.parseEther('2000')];
35
36
// The address of the token used to purchase this cover.
37
// Please check https://api.insurace.io/docs for a list of tokens that can be used to purchase covers.
38
const coverCurrency = '';
39
40
// The referral code used in this cover purchase, may be null.
41
const referralCode = null;
Copied!
  • httpApiCode: contact our technical team via Telegram, Discord, Forum or email to [email protected] to get the access code
  • productIds: Can be more than 1 IDs, which can be retrieved from Product List or by calling getProductList API
  • coverCurrency: token address can be retrieved by calling getCurrencyList API

Step 2: Call function

To buy covers, you need to use the following functions:
  • getCoverPremium()
Get the premium of the cover by calling getCoverPremium API with the parameters specified in Step 1 includes chain, productIds, coverDays, coverAmounts, coverCurrency, owner wallet address and referralCode.
1
async function getCoverPremium({ chain, productIds, coverDays, coverAmounts, coverCurrency, owner, referralCode }) {
2
const body = {
3
chain,
4
productIds,
5
coverDays,
6
coverAmounts,
7
coverCurrency,
8
owner,
9
referralCode,
10
};
11
12
const options = {
13
params: {
14
code: httpApiCode,
15
},
16
};
17
18
const { data } = await axios.post(httpApiUrl + '/getCoverPremium', body, options);
19
20
return {
21
premium: data.premiumAmount,
22
params: data.params,
23
};
24
}
Copied!
  • confirmCoverPremium()
Confirm the premium by calling confirmCoverPremiumAPI using the results getting from the above function as the parameter.
1
async function confirmCoverPremium({ chain, params }) {
2
const body = {
3
chain,
4
params,
5
};
6
7
const options = {
8
params: {
9
code: httpApiCode,
10
},
11
};
12
13
const { data } = await axios.post(httpApiUrl + '/confirmCoverPremium', body, options);
14
15
return {
16
params: data,
17
};
18
}
Copied!
  • buyCover()
Buy the cover with the confirmed information above.
1
async function buyCover(wallet, params) {
2
const contractAbi = [
3
'function buyCover(uint16[] products, uint16[] durationInDays, uint256[] amounts, address currency, address owner, uint256 referralCode, uint256 premiumAmount, uint256[] helperParameters, uint256[] securityParameters, uint8[] v, bytes32[] r, bytes32[] s) payable',
4
];
5
6
const contract = new Contract(contractAddress, contractAbi, wallet);
7
8
const response = await contract.buyCover(params[0], params[1], params[2], params[3], params[4], params[5], params[6], params[7], params[8], params[9], params[10], params[11]);
9
10
const receipt = await response.wait();
11
12
return receipt;
13
}
Copied!
Once done, you can call those functions in sequence. Here is a sample code for you:
1
// -------------------------------------------------------------------
2
// Main
3
// -------------------------------------------------------------------
4
5
async function main() {
6
const provider = new providers.JsonRpcProvider(jsonRpcUrl);
7
const wallet = new Wallet(privateKey, provider);
8
9
console.log('1. Get premium');
10
11
const premiumInfo = await getCoverPremium({
12
owner: wallet.address,
13
chain,
14
productIds,
15
coverDays,
16
coverAmounts,
17
coverCurrency,
18
referralCode,
19
});
20
21
console.log(`Premium = ${utils.formatEther(premiumInfo.premium)}`);
22
23
console.log('2. Confirm premium');
24
25
const confirmInfo = await confirmCoverPremium({
26
chain,
27
params: premiumInfo.params,
28
});
29
30
console.log('3. Purchase cover');
31
32
const receipt = await buyCover(wallet, confirmInfo.params);
33
34
console.log('Cover purchase successful.');
35
console.log(`Transaction hash: ${receipt.transactionHash}`);
36
}
37
38
main();
Copied!
Last modified 2mo ago