Skip to content

Instantly share code, notes, and snippets.

@raulk
Last active May 22, 2018 16:28
Show Gist options
  • Save raulk/de6ad3ab33ca2242e6698b6bad8e0572 to your computer and use it in GitHub Desktop.
Save raulk/de6ad3ab33ca2242e6698b6bad8e0572 to your computer and use it in GitHub Desktop.
system design: ethql queries by example
# here to give a title to this gist
{
# Select a block by number.
block(number: 1234) {
...BlockType
}
# Select a block by hash.
block(hash: "0x123...") {
...BlockType
}
# Select block by tag (BlockTag enum).
block(tag: LATEST) {
...BlockType
}
# Select the 100th block after 0x123...
block(offset: { hash: "0x123...", by: 100 }) {
...BlockType
}
# Select the 100th block before 1234.
block(offset: { number: 1234, by: -100 }) {
...BlockType
}
# Select all blocks between 1234 and 2345 inclusive.
blocks(numberRange: [1234, 2345]) {
[...BlockType]
}
# Select all blocks between 123 and 234 inclusive.
# Resolution: get block numbers of START and END in a batch, then continue resolving as numberRange.
blocks(hashRange: ["0x123...", "0x234..."]) {
[...BlockType]
}
# Select every nth block in the range.
blocks(...range, everyNth: 10) {
[...BlockType]
}
}
{
block(...) {
transaction(...) {
receipt
}
transactions(...) {
receipt
}
}
# Same inner queries as above.
blocks(...) {
}
transaction(hash: "0x1a2b3c...") {
receipt
}
}
{
# Starting from a block. See above.
block(...) {
# Select all transactions from this block.
transactions {
[...TransactionType]
}
# Select the 2nd transaction from each block.
transaction(index: 2) {
...TransactionType
}
# Select transactions sent from one address to another. User can provide both parameters or either, in which case the other will implicitly be a wildcard.
transactions(fromAddress: "0x123...", toAddress: "0x123...") {
[...TransactionType]
}
# Select transactions that involve any of the supplied participants.
transactions(participants: ["0x123...", "0x234...", "0x345..."]) {
[...TransactionType]
}
# Select all failed transactions. status argument is of type TransactionStatus.
# Resolution strategy: fetch transaction receipts.
transactions(status: FAILED) {
[...TransactionType]
}
# Select all transactions that emit logs and have an input.
transactions(withLogs: true, hasInput: true) {
[...TransactionType]
}
}
# Same inner selections possible as for a single block.
blocks(...) {
}
# Select a single transaction by hash.
transaction(hash: "0xa1b2c3...") {
...TransactionType
}
}
enum TransactionStatus {
SUCCESS,
FAILED
}
enum BlockTag {
EARLIEST,
LATEST,
PENDING
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment