Class Service

java.lang.Object
org.web3j.protocol.Service
All Implemented Interfaces:
Web3jService
Direct Known Subclasses:
HttpService, IpcService

public abstract class Service extends Object implements Web3jService
Base service implementation.
  • Field Details

    • objectMapper

      protected final com.fasterxml.jackson.databind.ObjectMapper objectMapper
  • Constructor Details

    • Service

      public Service(boolean includeRawResponses)
  • Method Details

    • performIO

      protected abstract InputStream performIO(String payload) throws IOException
      Throws:
      IOException
    • send

      public <T extends Response> T send(Request request, Class<T> responseType) throws IOException
      Description copied from interface: Web3jService
      Perform a synchronous JSON-RPC request.
      Specified by:
      send in interface Web3jService
      Type Parameters:
      T - type of a data item returned by the request
      Parameters:
      request - request to perform
      responseType - class of a data item returned by the request
      Returns:
      deserialized JSON-RPC response
      Throws:
      IOException - thrown if failed to perform a request
    • sendAsync

      public <T extends Response> CompletableFuture<T> sendAsync(Request jsonRpc20Request, Class<T> responseType)
      Description copied from interface: Web3jService
      Performs an asynchronous JSON-RPC request.
      Specified by:
      sendAsync in interface Web3jService
      Type Parameters:
      T - type of a data item returned by the request
      Parameters:
      jsonRpc20Request - request to perform
      responseType - class of a data item returned by the request
      Returns:
      CompletableFuture that will be completed when a result is returned or if a request has failed
    • sendBatch

      public BatchResponse sendBatch(BatchRequest batchRequest) throws IOException
      Description copied from interface: Web3jService
      Perform a synchronous JSON-RPC batch requests.
      Specified by:
      sendBatch in interface Web3jService
      Parameters:
      batchRequest - requests to perform
      Returns:
      deserialized JSON-RPC responses
      Throws:
      IOException - thrown if failed to perform a batch request
    • sendBatchAsync

      public CompletableFuture<BatchResponse> sendBatchAsync(BatchRequest batchRequest)
      Description copied from interface: Web3jService
      Performs an asynchronous JSON-RPC batch requests.
      Specified by:
      sendBatchAsync in interface Web3jService
      Parameters:
      batchRequest - batch request to perform
      Returns:
      CompletableFuture that will be completed when a result is returned or if a request has failed
    • subscribe

      public <T extends Notification<?>> io.reactivex.Flowable<T> subscribe(Request request, String unsubscribeMethod, Class<T> responseType)
      Description copied from interface: Web3jService
      Subscribe to a stream of notifications. A stream of notifications is opened by by performing a specified JSON-RPC request and is closed by calling the unsubscribe method. Different WebSocket implementations use different pair of subscribe/unsubscribe methods.

      This method creates an Flowable that can be used to subscribe to new notifications. When a client unsubscribes from this Flowable the service unsubscribes from the underlying stream of events.

      Specified by:
      subscribe in interface Web3jService
      Type Parameters:
      T - type of incoming event objects
      Parameters:
      request - JSON-RPC request that will be send to subscribe to a stream of events
      unsubscribeMethod - method that will be called to unsubscribe from a stream of notifications
      responseType - class of incoming events objects in a stream
      Returns:
      a Flowable instance that emits incoming events