Skip to content

dfuse-io/example-graphql-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dfuse GraphQL Java Example

This sample shows how one can use dfuse GraphQL API over gRPC to stream events out of the blockchain.

This particular sample showcase transaction lifecycle tracking to track all the lifecycle event that occurs for a given transaction, from pooled to fully confirmed.

Requirements

You will need to have Java 8 to run the example. This project uses Gradle as its build system. Gradle is not required as the Gradle wrapper is part of the project.

Quickstart

First of all, visit https://app.dfuse.io to get a free API key for your project.

First, clone this repository to your work folder:

git clone https://github.com/dfuse-io/example-graphql-java.git
cd example-graphql-java

Run the sample

./gradlew run --args='0xdd3eb631a5f6a66317356abd167c112b9ba6ccc92564fb4bd7391b3cb9a888aa'

Since this transaction above is already confirmed, not much events will be presented. For a better demo, the best is to create a raw transaction and obtain its hash, start the tracking process and then push the transaction to the chain.

You can also navigate to https://etherscan.io/txsPending?&m=&p=5, this is the fifth page of pending transactions, pick one there and use it above instead of the value.

Dependencies

This project uses Apache HttpClient for HTTP requests and FasterXML Jackson for JSON serialization/deserialization.

And of course, it depends on Protocol Buffers for the gRPC connection.

Protocol Buffers & gRPC

The definitions are automatically generated by the protobuf-gradle-plugin that takes care of invoking protoc with the right set of arguments to generate the Java sources files and the gRPC bindings.

A similar plugin exists for Maven build system protobuf-maven-plugin, this is given as a reference, it was not tested.

Otherwise, it's possible to invoke generate the definitions from the command line, you will need:

Ensure that both of these binaires are in your PATH:

$ which protoc
/usr/local/bin/protoc

$ which protoc-gen-grpc-java
/usr/local/bin/protoc-gen-grpc-java

Then you can generate the necessary files with the following command, we assume you are at the root of the project:

protoc -I=app/src/main/proto --java_out=app/src/main/java --grpc-java_out=app/src/main/java dfuse/graphql/v1/graphql.proto

Of course, it's recommended you integrate the generated files inside a different source set as well as making the generation automatic as part of your build system.

About

dfuse GraphQL Java Example - Transaction Lifecycle

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published