Skip to Content
dApps
On this page

eth_getTransactionByHash

Returns the information about a transaction by its hash.


Parameters

IndexTypeDescription
0stringTransaction hash (32 bytes)

Returns

object | null - Transaction object or null if not found

FieldTypeDescription
hashstringTransaction hash
noncestringSender’s nonce (hex)
blockHashstringBlock hash (null if pending)
blockNumberstringBlock number (null if pending)
transactionIndexstringIndex in block (null if pending)
fromstringSender address
tostringRecipient address (null for contract creation)
valuestringValue transferred (hex wei)
gasPricestringGas price (hex)
gasstringGas limit (hex)
inputstringTransaction data
vstringECDSA recovery id
rstringECDSA signature r
sstringECDSA signature s

Example

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') }

Track Transaction After Sending

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() }

Errors

CodeMessageDescription
-32602Invalid paramsInvalid transaction hash

Notes

  • Returns null if the transaction is not found
  • Pending transactions have null blockHash and blockNumber
  • For transaction status (success/failure), use eth_getTransactionReceipt
  • Transaction data persists even after the transaction is mined
Last updated on