Infura, the company offering free access to hosted Ethereum nodes has published another tool: EthQL.

EthQL is a GraphiQL tool which can be used to explore and query the Ethereum blockchain. GraphiQL is a browser based interface for querying GraphQL databases.

Let’s take a look at how it works and demonstrate some examples.

How to use EthQL

The left side of the screen contains queries while the result is printed on the right. Queries look like this:

query {
  block(number:1) {
    hash
  }
}
  • query means “start the query” and the query itself goes between the curly braces
  • block is one of the entities we can target for querying and matches a blockchain’s block
  • (number:1) means “first block”.
  • the information we need to extract can be specified with attributes in this body
  • hash is the unique combination of letters and numbers denoting validity and uniqueness of the block in question

In other words, this query means “give me the hash of the first Ethereum block”.

Example
Example

Example 1: Checking balances

Here’s how to check an address’ balance.

query {
  account(address:"0xbE2B28F870336B4eAA0aCc73cE02757fcC428dC9") {
    balance
    transactionCount
    code
  }
}
Balance checking
Balance checking

Example 2: Checking type

Some Ethereum addresses are external (i.e. they have a private key which unlocks them) while others are internal, on the blockchain only, like smart contracts. EthQL does have the type attribute but as this is alpha, it’s not very reliable and always returns null for now.

Edit: this has been fixed as of August 5th 2018!

Type
Type

There is another way to check type, though. The code attribute outputs the program code store on a given address. If this code is not 0x then we’re dealing with a smart contract, a program, and not an external address.

query {
  account(address:"0xb8f1437c742dc042af73d5bd18c8fc985ec8e3b4") {
    balance
    transactionCount
    type
    code
  }
}
Type
Type

Example 3: Detecting new transactions

Here’s how we can check when a specific account was involved with a new transaction.

query {
  block(number:6033927) {
    transactionsInvolving(participants:["0xbE2B28F870336B4eAA0aCc73cE02757fcC428dC9", "0x65e2c5175e2e618f48e70343b14c31b280e42d90"]) {
      from {address}
      to {address}
    }
  }
}

We use block(number: to specify a block for convenience and example here – because we know that the address 0x65... had a transaction in that block. transactionsInvolving will throw out all transactions that had something to do with any of the above listed addresses, outputting the sender and the recipient.

Tracking
Tracking

But how do we track the latest block for new transactions?

That’s what Tags are for.

query {
  block(tag:LATEST) {
    transactionsInvolving(participants:["0xbE2B28F870336B4eAA0aCc73cE02757fcC428dC9", "0x65e2c5175e2e618f48e70343b14c31b280e42d90"]) {
      from {address}
      to {address}
    }
  }
}

Now if we make a script on our server which periodically (say, every 10 seconds so the server doesn’t overload but still enough to catch every block) pings this query for new results, we’ll be able to build a notifier to let us know when an address is active. Then it’s just a matter of implementing it into Telegram or something similar.

Conclusion

EthQL is an interesting new tool for searching the Ethereum blockchain. The tool will, once it leaves alpha, no doubt be very handy in digital forensics. For more examples of syntax in GraphiQL see here and for a full list of the available data types in EthQL and their possible fields and attributes, make a query on the __schema object:

query {
  __schema {
    types {
      name
      kind
      description
      fields {
        name
        description
      }
    }
  }
}

Have you come up with any interesting queries?

LEAVE A REPLY

Please enter your comment!
Please enter your name here