Javascript integration
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
Last updated
Was this helpful?