5.4 Purchase Verified Node
Code Example: Purchase Verified Node
// async function purchaseVerifiedNode(connection, payer, nodeId, stakeAmount) {
const program = anchor.workspace.InsuranceDAO;
// Fetch Verified Node details
const verifiedNode = await program.account.verifiedNode.fetch(nodeId);
// Ensure sufficient funds for staking
if (payer.balance < stakeAmount) {
throw new Error('Insufficient balance to stake for this node');
}
// Prepare transaction to stake assets into Verified Node
const transaction = new anchor.web3.Transaction();
transaction.add(
program.instruction.purchaseVerifiedNode(
nodeId,
stakeAmount,
{
accounts: {
payer: payer.publicKey,
verifiedNode: verifiedNode.publicKey,
systemProgram: SystemProgram.programId,
},
}
)
);
// Send transaction to stake funds into the node
const signature = await connection.sendTransaction(transaction, [payer], { skipPreflight: false, preflightCommitment: 'confirmed' });
console.log(`Transaction confirmed with signature: ${signature}`);
}Last updated