circle-2Submit a quote

This step finalises the cover purchase by submitting the selected quote and its signature to the OpenCover Quote smart contract on the relevant L2 network using the user's connected wallet.

Submitting a quote involves potentially two transactions:

  1. ERC20 approval: If paying with an ERC20 token, prepare and execute an approve transaction.

  2. Quote submission: Prepare and execute the cover purchase transaction.

See the page below for the deployed contract addresses and ABI below.

file-signatureSmart contractschevron-right

Approve ERC20 transfer (if applicable)

If the payment is going to be made in an ERC20 token (USDC, USDT or cbBTC), the user needs to execute an approve transaction for spending the payment amount of that ERC20 token by the Quote contract.

  • Goal: Call the approve() function on the ERC20 token contract with the appropriate amount.

The example below uses wagmiarrow-up-right to approve purchasing a cover in USDC.

import { useWriteContract, useReadContract } from 'wagmi';

const quote = {}; // HTTP POST to https://opencover.com/api/quote, see "Get a quote"

// If a user decides to pay in USDC, find the corresponding payment quote
const paymentQuote = quote.quotes.find(q => q.premium.currency.symbol === 'USDC');

// Base mainnet Quote contract address
const contractAddress = '0xD68647555e5da198d50866334EEd647cbE3d1556';

// Read asset metadata to get ERC20 contract address
const { data: asset } = useReadContract({
    address: contractAddress,
    abi: QuoteAbi,
    functionName: 'assets',
    args: [quote.providerId, paymentQuote.premium.currency.assetId]
});
    
const { writeContract } = useWriteContract();

// Approve OpenCover Quote contract to allow ERC20 payment
writeContract({
    address: asset.assetAddress,
    abi: ERC20Abi,
    functionName: 'approve',
    args: [
        contractAddress,
        BigInt(paymentQuote.premium.value),
    ],
});

Submit selected quote

After the ERC20 approval is confirmed, create an onchain transaction that submits the selected quote and purchases protocol cover on using the Quote contract's submitQuoteV15()arrow-up-right function.

  • Goal: Call the submitQuoteV15() function on the OpenCover Quote contract using the quote fetched from the previous step.

The arguments to the submitQuoteV15() function are part of the API response from the Get a quote step.

Likewise, the QuoteSubmission structurearrow-up-right uses quote data returned from the Get a quote step.

The example code below uses wagmi to purchase a cover for 500 USDC on Aave v3 with the premium paid in USDC.

Track quote status

Once a quote is submitted onchain it is fulfilled and settled by OpenCover within 24 hours after which the cover becomes active and protection goes live. For more details on each quote state please visit our Quote lifecycle page.

The next step describes how to show users their submitted quotes, active and expired coverage.

Last updated