跳转到主要内容

getRecentBlockhash

此方法已弃用。请改用 getLatestBlockhash,它提供更准确和可靠的 blockhash 信息。
返回近期 blockhash 及其费用计划。此方法将在未来版本中移除。

参数

config
object

响应

result
object

迁移指南

要从 getRecentBlockhash 迁移到 getLatestBlockhash
  1. 替换方法调用:
  1. 更新费用计算:

代码示例

基本请求(旧版)

带 Commitment 的请求(旧版)

使用 web3.js(旧版)

注意事项

  1. 此方法已弃用,将在未来版本中移除
  2. 新开发请使用 getLatestBlockhash
  3. blockhash 有效期有限(通常为 150 个 slot)
  4. 可以指定不同的 commitment 级别
  5. 考虑更新现有代码以使用新方法

最佳实践

  1. 新开发迁移到 getLatestBlockhash
  2. 使用 getFeeForMessage 进行费用计算
  3. 使用 lastValidBlockHeight 监控 blockhash 过期
  4. 适当处理网络错误并重试
  5. 根据需求使用适当的 commitment 级别

常见错误

用例

  1. 交易费用计算
  2. Blockhash 监控
  3. 交易规划