Javascript integration

We’re using “bignumber.js”, but it works with other JS libraries for big numbers.

Buy Policy

//returns list of policies
let contract = new web3.eth.Contract(
        ContractRegistryAbi,
        ‘0x88240185a74F020B94b14FAe3e6d5DdE1AA9057b’
    );

return new web3.eth.Contract(PolicyBookRegistryContractAbi,
await contract.methods.getPolicyBookRegistryContract().call());

//returns approved contract from USDT
let contract = new web3.eth.Contract(
        PolicyBookFascade,
        id //id from 1st method (get list of policies)
    );

    //need to use number with decimals equal 18
        const bigNumberAmount = BigNumber(amount).times(BigNumber(10).pow(18)).toFixed();

    //returned total price
        contract.methods.getPolicyPrice(weeks, bigNumberAmount).call().then(res => {

    //returned USDT reserved amount contract
        getUSDTContract(web3).then(usdtContract => {
	//get allowance from USDT
        usdtContract.methods.allowance(userAddress, id).call().then(allowance => {
            //if allowance inccorrect need to call usdtContract.methods.approve(id , amount)
    })

})

//after the 2nd method there is a contract for buying policy
   //need to use number with decimals equal 18
       const bigNumberAmount = BigNumber(amount).times(BigNumber(10).pow(18)).toFixed();

contract.methods.buyPolicy(weeks, bigNumberAmount, referralAddress).send({from: userAddress}).then()

Provide Coverage

//returns list of policies
let contract = new web3.eth.Contract(
        ContractRegistryAbi,
        ‘0x88240185a74F020B94b14FAe3e6d5DdE1AA9057b’
    );

return new web3.eth.Contract(PolicyBookRegistryContractAbi,
await contract.methods.getPolicyBookRegistryContract().call());

//returns policy book
let contract = new web3.eth.Contract(
        PolicyBookContractAbi,
        id); //id from 1st method (get list of policies)

    const bigNumberAmount = BigNumber(amount).times(BigNumber(10).pow(18)).toFixed();
        // returned USDT reserved amount contract
        getUSDTContract(web3).then(usdtContract => {
	    //get allowance from USDT
        usdtContract.methods.allowance(userAddress, id).call().then(allowance => {
        //if allowance inccorrect need to call usdtContract.methods.approve(id , amount)
        })
    })

//after the 2nd method there is a contract for buying policy
   //need to use number with decimals equal 18
const bigNumberAmount = BigNumber(amount).times(BigNumber(10).pow(18)).toFixed();

//Provide coverage process
contract.methods.convertSTBLToBMIX(bigNumberAmount).call().then((BMIxAmount) => {
        contract.methods.allowance(userAddress, ‘0x6771Fd8968488Eb590Dff1730FE099c0eFA415bF’.call().then((allowance) => {

//check allowance equal amount
         if (BigNumber(allowance).lt(BMIxAmount)) {
             contract.methods.approve(‘0x6771Fd8968488Eb590Dff1730FE099c0eFA415bF’, BMIxAmount).send({from: userAddress}).then(() => {
                  contract.methods.addLiquidityAndStake(bigNumberAmount, bigNumberAmount).send({from: userAddress}).then(result => {
                      result
                    });
                })
            } else {
              contract.methods.addLiquidityAndStake(bigNumberAmount, bigNumberAmount).send({from: userAddress}).then(result => {
                      result
                });
            }
        })

    }

Last updated