このページの内容
eth_getTransactionReceipt
トランザクションハッシュに基づいてレシートを返します。レシートには、ステータスやログなどのトランザクション実行情報が含まれます。
パラメーター
| インデックス | 型 | 説明 |
|---|---|---|
| 0 | string | トランザクションハッシュ (32 バイト) |
戻り値
object | null - レシートオブジェクト。まだマイニングされていない場合は null
| フィールド | 型 | 説明 |
|---|---|---|
transactionHash | string | トランザクションハッシュ |
transactionIndex | string | ブロック内のインデックス (16 進数) |
blockHash | string | ブロックハッシュ |
blockNumber | string | ブロック番号 (16 進数) |
from | string | 送信者アドレス |
to | string | 受取人アドレス |
cumulativeGasUsed | string | このトランザクションまでにブロック内で使用されたガスの合計 |
gasUsed | string | このトランザクションが使用したガス (16 進数) |
contractAddress | string | 作成されたコントラクトアドレス (該当する場合) |
logs | array | ログオブジェクトの配列 |
logsBloom | string | ログのブルームフィルター |
status | string | 0x1 (成功) または 0x0 (失敗) |
effectiveGasPrice | string | 実際に支払われたガス価格 (16 進数) |
例
const receipt = await window.$onekey.ethereum.request({
method: 'eth_getTransactionReceipt',
params: ['0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b']
})
if (receipt) {
const success = receipt.status === '0x1'
console.log('Transaction', success ? 'succeeded' : 'failed')
console.log('Gas used:', parseInt(receipt.gasUsed, 16))
console.log('Logs:', receipt.logs.length)
}レシートを待機
async function waitForReceipt(txHash, timeout = 60000) {
const start = Date.now()
while (Date.now() - start < timeout) {
const receipt = await window.$onekey.ethereum.request({
method: 'eth_getTransactionReceipt',
params: [txHash]
})
if (receipt) {
return receipt
}
await new Promise(r => setTimeout(r, 2000))
}
throw new Error('Transaction receipt timeout')
}
// Usage
const txHash = await window.$onekey.ethereum.request({
method: 'eth_sendTransaction',
params: [txParams]
})
const receipt = await waitForReceipt(txHash)
console.log('Transaction status:', receipt.status === '0x1' ? 'Success' : 'Failed')コントラクトイベントを解析
// Set tokenAddress to the intended ERC-20 contract before parsing its Transfer logs.
const transferTopic = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'
const transferLogs = receipt.logs.filter(
log => log.address.toLowerCase() === tokenAddress.toLowerCase()
&& log.topics[0] === transferTopic
&& log.topics.length === 3
)
transferLogs.forEach(log => {
const from = '0x' + log.topics[1].slice(26)
const to = '0x' + log.topics[2].slice(26)
const value = BigInt(log.data).toString()
console.log(`Transfer: ${from} -> ${to}: ${value}`)
})エラー
| コード | メッセージ | 説明 |
|---|---|---|
| -32602 | 無効なパラメーター | 無効なトランザクションハッシュ |
注意事項
- 戻り値
null保留中のトランザクション (まだマイニングされていないもの) の場合 statusフィールド:0x1= 成功、0x0= リバートcontractAddressはコントラクト作成トランザクションにのみ存在しますlogsでトランザクションが発行したイベントを解析
ログをデコードする際は、発行元コントラクトと想定する ABI を確認してください。トピックの一致だけではトークンを識別できません。また、ERC-721 は同じ Transfer イベントシグネチャを、異なる indexed 構造で使用します。
最終更新日