# Java gRPC - Get Contract By ContractId

**URL:** <https://forum.canton.network/t/java-grpc-get-contract-by-contractid/4780>\
**Category:** App Development\
**Created:** [June 22, 2022, 4:20pm UTC](https://forum.canton.network/t/java-grpc-get-contract-by-contractid/4780 "2022-06-22T16:20:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![prajwalhegde3](https://avatars.discourse-cdn.com/v4/letter/p/dfb087/32.png) [@prajwalhegde3](https://forum.canton.network/u/prajwalhegde3)\
**Post date:** [June 22, 2022, 4:20pm UTC](https://forum.canton.network/t/java-grpc-get-contract-by-contractid/4780/1 "2022-06-22T16:20:47Z")

</div>

Hi All,

I’m trying to fetch contract by Id using Java gRPC. Can anyone help me understand what is the difference between TransactionFilter & InclusiveFilter

```haskell

TransactionServiceStub transactionService = TransactionServiceGrpc.newStub(channel);

		GetTransactionsRequest transactionsRequest = GetTransactionsRequest.newBuilder()
				.setLedgerId(grpcCommonObj.ledgerId)
				.setBegin(LedgerOffset.newBuilder().setBoundary(LedgerOffset.LedgerBoundary.LEDGER_BEGIN))
				.setFilter(TransactionFilter.newBuilder().putFiltersByParty(user, Filters.getDefaultInstance()))
				.build();

```

---

<div class="post-metadata">

**Author:** ![stefanobaghino-da](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/stefanobaghino-da/32/7057_2.png) [@stefanobaghino-da](https://forum.canton.network/u/stefanobaghino-da)\
**Post date:** [June 23, 2022, 7:49am UTC](https://forum.canton.network/t/java-grpc-get-contract-by-contractid/4780/2 "2022-06-23T07:49:58Z")

</div>

The `TransactionFilter` is an object that holds a generic predicate that you can use to filter flat transactions (i.e. contract state changes). Within it, you can have one of several possible predicates. In practice, right now this boils down to either `NoFilter` or an instance of `InclusiveFilter`, which specifies a positive predicate, in particular with regards to a set of template IDs. Note that you can filter by template ID only when querying for flat transactions (as you are doing in your snippet) but not for transaction trees (where the Ledger API querying capabilities are limited to specifying parties on behalf of which you’re reading).

---

<div class="post-metadata">

**Author:** ![prajwalhegde3](https://avatars.discourse-cdn.com/v4/letter/p/dfb087/32.png) [@prajwalhegde3](https://forum.canton.network/u/prajwalhegde3)\
**Post date:** [June 27, 2022, 5:06am UTC](https://forum.canton.network/t/java-grpc-get-contract-by-contractid/4780/3 "2022-06-27T05:06:51Z")

</div>

Thanks for the explanation @stefanobaghino-da.

But I’m still unable to achieve the filtering of contracts by Id. Any help with the code is appreciated.

Thank you!!

---

<div class="post-metadata">

**Author:** ![cocreature](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/cocreature/32/36_2.png) [@cocreature](https://forum.canton.network/u/cocreature)\
**Post date:** [June 27, 2022, 5:08am UTC](https://forum.canton.network/t/java-grpc-get-contract-by-contractid/4780/4 "2022-06-27T05:08:21Z")

</div>

There is no server side filtering by contract id via the gRPC API. You have to fetch all contracts of a given template and filter on the client side. If you do that frequently, you can keep a custom ods and index by contract id to make that more efficient.

---

<div class="post-metadata">

**Author:** ![prajwalhegde3](https://avatars.discourse-cdn.com/v4/letter/p/dfb087/32.png) [@prajwalhegde3](https://forum.canton.network/u/prajwalhegde3)\
**Post date:** [June 27, 2022, 5:12am UTC](https://forum.canton.network/t/java-grpc-get-contract-by-contractid/4780/5 "2022-06-27T05:12:41Z")

</div>

Thank you @cocreature
