Sur cette page
eth_getTransactionByHash
Renvoie les informations d’une transaction à partir de son hash.
Paramètres
| Indice | Type | Description |
|---|---|---|
| 0 | string | Hash de transaction (32 octets) |
Valeur de retour
object | null - Objet de transaction ou null si la transaction est introuvable
| Champ | Type | Description |
|---|---|---|
hash | string | Hash de transaction |
nonce | string | Nonce de l’expéditeur (hex) |
blockHash | string | Hash de bloc (null si en attente) |
blockNumber | string | Numéro de bloc (null si en attente) |
transactionIndex | string | Indice dans le bloc (null si en attente) |
from | string | Adresse de l’expéditeur |
to | string | Adresse du destinataire (null pour la création d’un contrat) |
value | string | Valeur transférée (wei en hex) |
gasPrice | string | Prix du gas (hex) |
gas | string | Limite de gas (hex) |
input | string | Données de transaction |
v | string | Identifiant de récupération ECDSA |
r | string | Composante r de la signature ECDSA |
s | string | Composante s de la signature ECDSA |
Exemple
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')
}Suivre une transaction après l’envoi
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()
}Erreurs
| Code | Message | Description |
|---|---|---|
| -32602 | Paramètres non valides | Hash de transaction non valide |
Remarques
- Renvoie
nullsi la transaction est introuvable - Les transactions en attente ont null pour
blockHashetblockNumber - Pour le statut de la transaction (réussite/échec), utilisez eth_getTransactionReceipt
- Les données de transaction persistent même après son minage
Dernière mise à jour le