Java_query

 avatar
unknown
java
a year ago
2.4 kB
11
Indexable
package org.example;


import okhttp3.*;

import java.io.IOException;

public class BitqueryWebsocketClient {

    private static final String BEARER_TOKEN = "*************************************************";

    private final OkHttpClient client;
    private final MediaType mediaType;
    private final RequestBody body;
    private final Request request;

    public BitqueryWebsocketClient() {
        client = new OkHttpClient().newBuilder().build();
        mediaType = MediaType.parse("application/json");

        String jsonBody = "{"
                + "\"query\":\"query BalanceUpdateNewHolderOrPositionUp($netzwerk: evm_network!, $tokenContractAddress: String!, $fromAddress: String!) {"
                + "  EVM(network: $netzwerk, dataset: combined) {"
                + "    BalanceUpdates("
                + "      where: {Currency: {SmartContract: {is: $tokenContractAddress}}, BalanceUpdate: {Address: {is: $fromAddress}}}"
                + "    ) {"
                + "      BalanceUpdate {"
                + "        Address"
                + "      }"
                + "      Balance: sum(of: BalanceUpdate_Amount)"
                + "    }"
                + "  }"
                + "}\","
                + "\"variables\":{"
                + "\"fromAddress\":\"0x2c7737b55557e9be17240183fef5c1d377a581c4\","
                + "\"tokenContractAddress\":\"0xd1f17b7a6bff962659ed608bcd6d318bb5fbb249\","
                + "\"netzwerk\":\"eth\""
                + "}"
                + "}";
        body = RequestBody.create(mediaType, jsonBody);

        request = new Request.Builder()
                .url("https://streaming.bitquery.io/graphql")
                .method("POST", body)
                .header("Authorization", "Bearer " + BEARER_TOKEN)
                .header("Content-Type", "application/json")
                .build();
    }

    public void executeRequest() {
        try {
            Response response = client.newCall(request).execute();
            System.out.println(response.body().string());
            response.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        BitqueryWebsocketClient client = new BitqueryWebsocketClient();
        client.executeRequest();
    }
}
Editor is loading...
Leave a Comment