Interface Gateway

All Superinterfaces:
AutoCloseable

public interface Gateway extends AutoCloseable
The Gateway provides the connection point for an application to access the Fabric network as a specific user. It is instantiated from a Builder instance that is created using newInstance(), and configured using a gateway URL and a signing identity. It can then be connected to a fabric network using the Builder's connect() method. Once connected, it can then access individual Network instances (channels) using the getNetwork() method which in turn can access the Contract installed on a network and submit transactions to the ledger.

Gateway instances should be reused for multiple transaction invocations and only closed once connection to the Fabric network is no longer required.

Multiple Gateway instances may share the same underlying gRPC connection by supplying the gRPC Channel as an option to the Gateway connect.


     Identity identity = new X509Identity("mspId", certificate);
     Signer signer = Signers.newPrivateKeySigner(privateKey);

     Gateway.Builder builder = Gateway.newInstance()
             .identity(identity)
             .signer(signer)
             .connection(grpcChannel);

     try (Gateway gateway = builder.connect()) {
         Network network = gateway.getNetwork("channel");
         // Interactions with the network
     }
 
  • Method Details

    • newInstance

      static Gateway.Builder newInstance()
      Creates a gateway builder which is used to configure and connect a new Gateway instance.
      Returns:
      A gateway builder.
    • getIdentity

      Identity getIdentity()
      Returns the identity used to interact with Fabric.
      Returns:
      A client identity.
    • getNetwork

      Network getNetwork(String networkName)
      Returns an object representing a network.
      Parameters:
      networkName - The name of the network (channel name)
      Returns:
      A network.
      Throws:
      NullPointerException - if the network name is null.
    • newSignedProposal

      Proposal newSignedProposal(byte[] proposalBytes, byte[] signature)
      Create a proposal with the specified digital signature. Supports off-line signing flow.
      Parameters:
      proposalBytes - The proposal.
      signature - A digital signature.
      Returns:
      A signed proposal.
      Throws:
      IllegalArgumentException - if the supplied proposal bytes are not a valid proposal.
    • newProposal

      Proposal newProposal(byte[] proposalBytes)
      Recreates a proposal from serialized data.
      Parameters:
      proposalBytes - The proposal.
      Returns:
      A proposal.
      Throws:
      IllegalArgumentException - if the supplied proposal bytes are not a valid proposal.
    • newSignedTransaction

      Transaction newSignedTransaction(byte[] transactionBytes, byte[] signature)
      Create a transaction with the specified digital signature. Supports off-line signing flow.
      Parameters:
      transactionBytes - The transaction.
      signature - A digital signature.
      Returns:
      A signed transaction.
      Throws:
      IllegalArgumentException - if the supplied transaction bytes are not a valid transaction.
    • newTransaction

      Transaction newTransaction(byte[] transactionBytes)
      Recreates a transaction from serialized data.
      Parameters:
      transactionBytes - The transaction.
      Returns:
      A transaction.
      Throws:
      IllegalArgumentException - if the supplied transaction bytes are not a valid transaction.
    • newSignedCommit

      Commit newSignedCommit(byte[] bytes, byte[] signature)
      Create a commit with the specified digital signature, which can be used to access information about a transaction that is committed to the ledger. Supports off-line signing flow.
      Parameters:
      bytes - Serialized commit status request.
      signature - Digital signature.
      Returns:
      A signed commit status request.
      Throws:
      IllegalArgumentException - if the supplied commit bytes are not a valid commit.
    • newCommit

      Commit newCommit(byte[] bytes)
      Recreates a commit from serialized data.
      Parameters:
      bytes - Serialized commit status request.
      Returns:
      A signed commit status request.
      Throws:
      IllegalArgumentException - if the supplied commit bytes are not a valid commit.
    • newSignedChaincodeEventsRequest

      ChaincodeEventsRequest newSignedChaincodeEventsRequest(byte[] bytes, byte[] signature)
      Create a chaincode events request with the specified digital signature, which can be used to obtain events emitted by transaction functions of a specific chaincode. Supports off-line signing flow.
      Parameters:
      bytes - Serialized chaincode events request.
      signature - Digital signature.
      Returns:
      A signed chaincode events request.
      Throws:
      IllegalArgumentException - if the supplied chaincode events request bytes are not valid.
    • newChaincodeEventsRequest

      ChaincodeEventsRequest newChaincodeEventsRequest(byte[] bytes)
      Recreates a chaincode events request from serialized data.
      Parameters:
      bytes - Serialized chaincode events request.
      Returns:
      A chaincode events request.
      Throws:
      IllegalArgumentException - if the supplied chaincode events request bytes are not valid.
    • newSignedBlockEventsRequest

      BlockEventsRequest newSignedBlockEventsRequest(byte[] bytes, byte[] signature)
      Create a block events request with the specified digital signature, which can be used to receive block events. Supports off-line signing flow.
      Parameters:
      bytes - Serialized block events request.
      signature - Digital signature.
      Returns:
      A signed block events request.
      Throws:
      IllegalArgumentException - if the supplied request bytes are not valid.
    • newBlockEventsRequest

      BlockEventsRequest newBlockEventsRequest(byte[] bytes)
      Recreates a block events request from serialized bytes.
      Parameters:
      bytes - Serialized block events request.
      Returns:
      A block events request.
      Throws:
      IllegalArgumentException - if the supplied request bytes are not valid.
    • newSignedFilteredBlockEventsRequest

      FilteredBlockEventsRequest newSignedFilteredBlockEventsRequest(byte[] bytes, byte[] signature)
      Create a filtered block events request with the specified digital signature, which can be used to receive filtered block events.* Supports off-line signing flow.
      Parameters:
      bytes - Serialized filtered block events request.
      signature - Digital signature.
      Returns:
      A signed filtered block events request.
      Throws:
      IllegalArgumentException - if the supplied request bytes are not valid.
    • newFilteredBlockEventsRequest

      FilteredBlockEventsRequest newFilteredBlockEventsRequest(byte[] bytes)
      Recreates a filtered block event request from serialized data.
      Parameters:
      bytes - Serialized filtered block events request.
      Returns:
      A filtered block events request.
      Throws:
      IllegalArgumentException - if the supplied request bytes are not valid.
    • newSignedBlockAndPrivateDataEventsRequest

      BlockAndPrivateDataEventsRequest newSignedBlockAndPrivateDataEventsRequest(byte[] bytes, byte[] signature)
      Create a block and private data events request with the specified digital signature, which can be used to receive block and private data events. Supports off-line signing flow.
      Parameters:
      bytes - Serialized block and private data events request.
      signature - Digital signature.
      Returns:
      A signed block and private data events request.
      Throws:
      IllegalArgumentException - if the supplied request bytes are not valid.
    • newBlockAndPrivateDataEventsRequest

      BlockAndPrivateDataEventsRequest newBlockAndPrivateDataEventsRequest(byte[] bytes)
      Recreate a block and private data events request from serialized data.
      Parameters:
      bytes - Serialized block and private data events request.
      Returns:
      A block and private data events request.
      Throws:
      IllegalArgumentException - if the supplied request bytes are not valid.
    • close

      void close()
      Close the gateway connection and all associated resources, including removing listeners attached to networks and contracts created by the gateway.
      Specified by:
      close in interface AutoCloseable