Q12 · 区块链基础
"等几个块确认"是什么意思?
⚡ 速记答案(30 秒)
- 一笔交易被打包进第 N 个区块后,后续每多出一个新区块,就多一次"确认"
- 等待若干确认是为了防止链回滚 / 分叉,确认数越多,交易被回滚的概率越低
- 不同业务场景设置不同确认数:转账可能 1-3 个,交易所充值常见 12 个以上
📖 详细讲解
确认数与安全性
区块 N → 交易被打包 (0 确认)
区块 N+1 → 1 确认
区块 N+2 → 2 确认
...
区块 N+6 → 6 确认 (比特币推荐)不同链的推荐确认数
| 链 | 出块时间 | 推荐确认数 | 等待时间 |
|---|---|---|---|
| Bitcoin | ~10 分钟 | 6 | ~1 小时 |
| Ethereum | ~12 秒 | 12-32 | ~3-6 分钟 |
| BSC | ~3 秒 | 15 | ~45 秒 |
前端处理示例
• 监听交易状态
• 显示确认进度
• 处理交易失败
面试要点
• 为什么比特币需要 6 个确认
• 以太坊 Finality 的概念
• 51% 攻击与确认数的关系
💻 代码示例
等待交易确认
import { ethers } from 'ethers';
async function sendWithConfirmations(
signer: ethers.Signer,
to: string,
value: bigint,
confirmations: number = 3
) {
// 发送交易
const tx = await signer.sendTransaction({ to, value });
console.log('交易已发送:', tx.hash);
// 等待指定确认数
const receipt = await tx.wait(confirmations);
console.log(`交易已确认 ${confirmations} 次`);
console.log('区块号:', receipt?.blockNumber);
return receipt;
}面试技巧:回答时先给出核心结论,再展开细节。如果有实际项目经验,一定要结合具体案例说明。