Last active
October 6, 2022 16:48
-
-
Save ryanschneider/e7819ff02256138b780969ddf114a0e7 to your computer and use it in GitHub Desktop.
EthQL transaction confirmation via subscription
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# offline, sign a transaction to generate it's raw bytes 0xRAWTX | |
# connect to our new transaction websocket endpoint | |
# send the graphql mutation: | |
mutatation { | |
sendRawTransaction(data: "0xRAWTX") { | |
hash | |
} | |
} | |
# get back the hash or an error | |
{ | |
hash: "0xHASH" | |
} | |
# subscribe to updates on the 0xHASH until it's been confirmed for 3 blocks | |
subscription { | |
transaction(hash: 0xHASH, untilConfirmationDepth: 3) { | |
confirmationDepth | |
block { | |
hash | |
number | |
} | |
} | |
} | |
# get back block null since it's unconfirmed | |
{ | |
confirmationDepth: null, | |
block: null | |
} | |
# once it's mined | |
{ | |
confirmationDepth: 1, | |
block { | |
hash: 0xBLOCK, | |
number: 0x698765 | |
} | |
} | |
# .. and another tick once it's been confirmed for one block | |
{ | |
confirmationDepth: 2, | |
block { | |
hash: 0xBLOCK, | |
number: 0x698765 | |
} | |
} | |
# if there's a rollback and it's unconfirmed | |
{ | |
confirmationDepth: null, | |
block: null, | |
} | |
# but then another reorg and it's back in the chain | |
{ | |
confirmationDepth: 3, | |
block { | |
hash: 0xBLOCK2, | |
number: 0x698766 | |
} | |
} | |
# at that point, confirmationDepth == subscription.untilConfirmationDepth, so you won't get any more updates |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment