Skip to Content
dApps
Auf dieser Seite

eth_getTransactionByHash

Gibt Informationen zu einer Transaktion anhand ihres Hashs zurück.


Parameter

IndexTypBeschreibung
0stringTransaktionshash (32 Bytes)

Rückgabe

object | null - Transaktionsobjekt oder null, wenn nicht gefunden

FeldTypBeschreibung
hashstringTransaktionshash
noncestringNonce des Absenders (hex)
blockHashstringBlockhash (null, wenn ausstehend)
blockNumberstringBlocknummer (null, wenn ausstehend)
transactionIndexstringIndex im Block (null, wenn ausstehend)
fromstringAbsenderadresse
tostringEmpfängeradresse (null bei Vertragserstellung)
valuestringÜbertragener Wert (hexadezimale Wei)
gasPricestringGaspreis (hex)
gasstringGaslimit (hex)
inputstringTransaktionsdaten
vstringECDSA-Recovery-ID
rstringECDSA-Signatur r
sstringECDSA-Signatur s

Beispiel

const tx = await window.$onekey.ethereum.request({ method: 'eth_getTransactionByHash', params: ['0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b'] }) if (tx) { console.log('From:', tx.from) console.log('To:', tx.to) console.log('Value:', BigInt(tx.value).toString()) console.log('Status:', tx.blockHash ? 'Mined' : 'Pending') }

Transaktion nach dem Senden verfolgen

async function sendAndTrack(txParams, timeoutMs = 60000) { const deadline = Date.now() + timeoutMs // Send transaction const txHash = await window.$onekey.ethereum.request({ method: 'eth_sendTransaction', params: [txParams] }) console.log('Transaction sent:', txHash) // Poll for transaction details const checkTx = async () => { if (Date.now() >= deadline) throw new Error("Transaction lookup timed out") const tx = await window.$onekey.ethereum.request({ method: 'eth_getTransactionByHash', params: [txHash] }) if (tx && tx.blockHash) { console.log('Transaction mined in block:', parseInt(tx.blockNumber, 16)) return tx } // Still pending, check again await new Promise(r => setTimeout(r, 2000)) return checkTx() } return checkTx() }

Fehler

CodeNachrichtBeschreibung
-32602Ungültige ParameterUngültiger Transaktionshash

Hinweise

  • Gibt null zurück, wenn die Transaktion nicht gefunden wird
  • Ausstehende Transaktionen haben null für blockHash und blockNumber
  • Für den Transaktionsstatus (Erfolg/Fehlschlag) verwenden Sie eth_getTransactionReceipt
  • Transaktionsdaten bleiben auch nach Aufnahme der Transaktion in einen Block erhalten
Zuletzt aktualisiert am