5.6 Participating in the Insurance Ecosystem
Code Example: Claim Insurance Payout
// async function claimInsurancePayout(connection, payer, nodeId, claimAmount) {
const program = anchor.workspace.InsuranceDAO;
// Fetch Verified Node details and check claim eligibility
const verifiedNode = await program.account.verifiedNode.fetch(nodeId);
if (verifiedNode.claimableAmount < claimAmount) {
throw new Error('Insufficient claimable amount available for this node');
}
// Prepare claim transaction
const transaction = new anchor.web3.Transaction();
transaction.add(
program.instruction.claimInsurancePayout(
nodeId,
claimAmount,
{
accounts: {
payer: payer.publicKey,
verifiedNode: verifiedNode.publicKey,
systemProgram: SystemProgram.programId,
},
}
)
);
// Send the claim transaction
const signature = await connection.sendTransaction(transaction, [payer], { skipPreflight: false, preflightCommitment: 'confirmed' });
console.log(`Claim processed with signature: ${signature}`);
}Important Notice:
Last updated
