# Alchemy 查交易回执是 null：区分错误网络、未入块和执行失败

整理：链小知（AI 辅助）
资料核对日期：2026-10-12
引用地址：https://lianxiaozhi.com/tools/guides/alchemy-transaction-receipt-null
难度：进阶
核验方式：官方文档整理，未执行真实账户操作

核对 JSON-RPC 链身份、交易对象与 receipt，避免把 HTTP 200 或哈希存在当执行成功。

## 使用工具
- [Alchemy](https://lianxiaozhi.com/tools/alchemy) · [官方入口](https://www.alchemy.com/docs)

## 前置条件
- 准备 Ethereum 交易哈希及已保存的 eth_chainId、eth_getTransactionByHash、eth_getTransactionReceipt 响应。
- RPC endpoint 包含 API key，分享前脱敏；查询计入服务用量，额度和收费按当前套餐，其他链功能需单独核对。

## 1. 先验证 endpoint 网络

读 eth_chainId 响应的十六进制链 ID。Ethereum Mainnet 为 0x1；endpoint 的链身份必须与交易来源匹配。官方示例中的数据只用来说明字段，不能当目标交易真实证据。

核对结果：链 ID 与目标交易网络一致，key 未暴露。
依据：[Alchemy eth_chainId](https://www.alchemy.com/docs/chains/ethereum/ethereum-api-endpoints/eth-chain-id)

## 2. 校验交易哈希与 JSON-RPC envelope

输入应为 0x 加 64 位十六进制交易哈希。检查响应的 id、result 和 error；HTTP 200 仅是传输结果，JSON-RPC error 仍需排查参数、权限或节点问题。

核对结果：使用完整哈希，error 未被当作成功空结果。
依据：[Alchemy eth_getTransactionByHash](https://www.alchemy.com/docs/chains/ethereum/ethereum-api-endpoints/eth-get-transaction-by-hash)
依据：[Ethereum JSON-RPC：交易与回执字段](https://ethereum.org/developers/docs/apis/json-rpc/)

## 3. 比较交易对象与回执是否存在

eth_getTransactionByHash 回答节点是否知道该交易，receipt 回答入块执行结果。交易对象若未入块，blockHash/blockNumber 可能为空；receipt 为 null 不能证明执行失败，先检查网络和是否尚未入块。

核对结果：“找到交易”和“取得回执”有各自状态。
依据：[Alchemy eth_getTransactionByHash](https://www.alchemy.com/docs/chains/ethereum/ethereum-api-endpoints/eth-get-transaction-by-hash)
依据：[Ethereum JSON-RPC：交易与回执字段](https://ethereum.org/developers/docs/apis/json-rpc/)

## 4. 回执非空再读 status 与 logs

核对 receipt.transactionHash、blockHash、blockNumber、status 和 logs。status 0x1/0x0 区分执行成功/失败，但成功回执不等于期望代币一定到账；仍需根据目标合约 ABI 检查日志和接收地址。

核对结果：执行状态与具体业务结果没有合并。
依据：[Alchemy eth_getTransactionReceipt](https://www.alchemy.com/docs/chains/ethereum/ethereum-api-endpoints/eth-get-transaction-receipt)
依据：[Ethereum JSON-RPC：交易与回执字段](https://ethereum.org/developers/docs/apis/json-rpc/)

## 5. 分开 gas、查询成本和确认范围

gasUsed × effectiveGasPrice 可核对执行网络成本，十六进制需正确换算；RPC Compute Units 是服务查询计量，不能当链上 gas。保留区块与取得时间，交易回执不单独证明跨链另一端已完成或永久不会重组。

核对结果：记录网络成本、服务用量及最终性未验证项。
依据：[Alchemy eth_getTransactionReceipt](https://www.alchemy.com/docs/chains/ethereum/ethereum-api-endpoints/eth-get-transaction-receipt)
依据：[Ethereum JSON-RPC：交易与回执字段](https://ethereum.org/developers/docs/apis/json-rpc/)

## 常见错误
- HTTP 200 视作链上成功。
- receipt null 一律判成失败或丢失。
- 将 Alchemy CU 当 gas 费用。

## 完成检查
- 对链、哈希、交易对象与回执给出一致的诊断。
- 业务到账与最终性保留各自核查状态。

## 相关知识

## 官方依据
- [Alchemy eth_chainId](https://www.alchemy.com/docs/chains/ethereum/ethereum-api-endpoints/eth-chain-id)
- [Alchemy eth_getTransactionByHash](https://www.alchemy.com/docs/chains/ethereum/ethereum-api-endpoints/eth-get-transaction-by-hash)
- [Alchemy eth_getTransactionReceipt](https://www.alchemy.com/docs/chains/ethereum/ethereum-api-endpoints/eth-get-transaction-receipt)
- [Ethereum JSON-RPC：交易与回执字段](https://ethereum.org/developers/docs/apis/json-rpc/)
