# Bond Trading + TS : what is the type?

**URL:** <https://forum.canton.network/t/bond-trading-ts-what-is-the-type/3100>\
**Category:** App Development\
**Tags:** daml, react\
**Created:** [September 10, 2021, 9:52am UTC](https://forum.canton.network/t/bond-trading-ts-what-is-the-type/3100 "2021-09-10T09:52:58Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hem-M](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/hem-m/32/2044_2.png) [@Hem-M](https://forum.canton.network/u/Hem-M)\
**Post date:** [September 10, 2021, 9:52am UTC](https://forum.canton.network/t/bond-trading-ts-what-is-the-type/3100/1 "2021-09-10T09:52:58Z")

</div>

Hi All,  
I have worked on [“daml-ui-template”](https://github.com/digital-asset/daml-ui-template) where the templates were stuffed in Main.  
Currently, I am working on [“ex-bond-trading”](https://github.com/digital-asset/ex-bond-trading) sample from daml repo and facing type issues while querying templates(Bond, Cash, Dvp etc).  
Below are the code and error I’m stuck at trying out types to assign.

**UPDATED**  
Also to mention, I have seperated daml and UI projects. I start daml and then run codegen to generate daml.js at UI project (which creates @daml.js/ex-bond-trading-3.0.0) and then start UI.

```haskell
import **BondImp** from "@daml.js/ex-bond-trading-3.0.0/lib/Bond";
**import { useQuery } from "@daml/react";**

function Bond{ 
    ...
    const bonds = useQuery( **BondImp** );
    console.log(bonds.contracts);
}

```

> Error:  
> Argument of type ‘typeof import(“/home/…/ex-bond-trading-UI-react/node\_modules/@daml.js/ex-bond-trading-3.0.0/lib/Bond/index”)’ is not assignable to parameter of type ‘Template\<object, unknown, string\>’.  
> Type ‘typeof import(“/home/…/ex-bond-trading-UI-react/node\_modules/@daml.js/ex-bond-trading-3.0.0/lib/Bond/index”)’ is missing the following properties from type ‘Template\<object, unknown, string\>’: templateId, sdkVersion, keyDecoder, keyEncode, and 3 more. TS2345

Seeking for help in this forum since it’s a sample taken from DAML repo.  
Any help is appreciated.

---

<div class="post-metadata">

**Author:** ![Gary\_Verhaegen](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/gary_verhaegen/32/81_2.png) [@Gary\_Verhaegen](https://forum.canton.network/u/Gary_Verhaegen)\
**Post date:** [September 10, 2021, 9:58am UTC](https://forum.canton.network/t/bond-trading-ts-what-is-the-type/3100/2 "2021-09-10T09:58:52Z")

</div>

It’s hard to be sure without access to more of your code, but I’d first point out that you’re defining a function with the same name as an import, and that’s bound to confuse both the TS type-checker and readers of your code, as they live in the same namespace. I would strongly recommend not doing that.

---

<div class="post-metadata">

**Author:** ![Hem-M](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/hem-m/32/2044_2.png) [@Hem-M](https://forum.canton.network/u/Hem-M)\
**Post date:** [September 10, 2021, 12:32pm UTC](https://forum.canton.network/t/bond-trading-ts-what-is-the-type/3100/3 "2021-09-10T12:32:50Z")

</div>

//It’s hard to be sure without access to more of your code  
Snippet in the question is all the code.  
I am trying to query all the active Bond contracts with daml/react.  
When “ex-bond-trading” is executed as per the doc provided, the Bank has 10Bond and 10Cash active contracts.

 ![Screenshot from 2021-09-10 18-07-46](https://canada1.discourse-cdn.com/flex028/uploads/daml/original/2X/0/0aed05a481fd5b3578d731117f5cd397a7e6d1f2.png)

I am trying to query the Bond and Cash using above snippet.

// I would strongly recommend not doing that  
I have made changes in the question

---

<div class="post-metadata">

**Author:** ![Gary\_Verhaegen](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/gary_verhaegen/32/81_2.png) [@Gary\_Verhaegen](https://forum.canton.network/u/Gary_Verhaegen)\
**Post date:** [September 10, 2021, 2:05pm UTC](https://forum.canton.network/t/bond-trading-ts-what-is-the-type/3100/4 "2021-09-10T14:05:40Z")

</div>

> [@Hem-M](#):
>
> I have made changes in the question

Does changing the name of the import change the error message you get?

---

<div class="post-metadata">

**Author:** ![Hem-M](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/hem-m/32/2044_2.png) [@Hem-M](https://forum.canton.network/u/Hem-M)\
**Post date:** [September 10, 2021, 3:17pm UTC](https://forum.canton.network/t/bond-trading-ts-what-is-the-type/3100/5 "2021-09-10T15:17:13Z")

</div>

```haskell
import bond from "@daml.js/ex-bond-trading-3.0.0/lib/Bond";
import BondImp from "@daml.js/ex-bond-trading-3.0.0/lib/Bond";
import { Cash } from "@daml.js/ex-bond-trading-3.0.0/lib/Cash";
import { useQuery } from "@daml/react";
function Market() {
  const bonds = useQuery(BondImp);
}

```

> Error  
> Argument of type ‘typeof import(“/home/…/ex-bond-trading-UI-react/node\_modules/@daml.js/ex-bond-trading-3.0.0/lib/Bond/index”)’ is not assignable to parameter of type ‘Template\<object, unknown, string\>’.  
> Type ‘typeof import(“/home/…/ex-bond-trading-UI-react/node\_modules/@daml.js/ex-bond-trading-3.0.0/lib/Bond/index”)’ is missing the following properties from type ‘Template\<object, unknown, string\>’: templateId, sdkVersion, keyDecoder, keyEncode, and 3 more.ts(2345)

```haskell
import { Bond } from "@daml.js/ex-bond-trading-3.0.0/lib/Bond";
import { Cash } from "@daml.js/ex-bond-trading-3.0.0/lib/Cash";
import { useQuery } from "@daml/react";
function Market() {
  const bonds = useQuery(Bond);
}

```

> Error  
> Argument of type ‘Template\<Bond, undefined, “a47bd7215c9a7a019f4cf03b9c95e501407c0c21515032846ceb37c5f8f086fa:Bond:Bond”\> & { Split: Choice\<Bond, Split, Tuple2\<ContractId, ContractId\<…\>\>, undefined\>; Merge: Choice\<…\>; Archive: Choice\<…\>; Transfer: Choice\<…\>; }’ is not assignable to parameter of type ‘Template\<object, unknown, string\>’.  
> Type ‘Template\<Bond, undefined, “a47bd7215c9a7a019f4cf03b9c95e501407c0c21515032846ceb37c5f8f086fa:Bond:Bond”\> & { Split: Choice\<Bond, Split, Tuple2\<ContractId, ContractId\<…\>\>, undefined\>; Merge: Choice\<…\>; Archive: Choice\<…\>; Transfer: Choice\<…\>; }’ is missing the following properties from type ‘Template\<object, unknown, string\>’: sdkVersion, keyEncode, encodets(2345)  
> (alias) namespace Bond  
> (alias) const Bond: damlTypes.Template\<Bond, undefined, “a47bd7215c9a7a019f4cf03b9c95e501407c0c21515032846ceb37c5f8f086fa:Bond:Bond”\> & {  
> Split: damlTypes.Choice\<Bond, Split, pkg40f452260bef3f29dede136108fc08a88d5a5250310281067087da6f0baddff7.DA.Types.Tuple2\<…\>, undefined\>;  
> Merge: damlTypes.Choice\<…\>;  
> Archive: damlTypes.Choice\<…\>;  
> Transfer: damlTypes.Choice\<…\>;  
> }  
> import Bond

---

<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:** [September 13, 2021, 6:19am UTC](https://forum.canton.network/t/bond-trading-ts-what-is-the-type/3100/6 "2021-09-13T06:19:51Z")

</div>

This looks like you might be running into an issue in an older version of the typscript libraries (ex-bond-trading is still on version 1.5.0). I recommend upgrading the SDK and the correspondng typescript libraries to 1.16.0.

---

<div class="post-metadata">

**Author:** ![Hem-M](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/hem-m/32/2044_2.png) [@Hem-M](https://forum.canton.network/u/Hem-M)\
**Post date:** [September 13, 2021, 9:06am UTC](https://forum.canton.network/t/bond-trading-ts-what-is-the-type/3100/7 "2021-09-13T09:06:33Z")

</div>

bingo… That was it.  
I have a follow up question.  
The application shows 10 count beside Bond template, as you can check in the image shared above, but when I query Bond template it responds with zero size contract array.

**No error**

```haskell
const bonds = useQuery(Bond); *or useStreamQueries(Bond);*
console.log(bonds);

```

> o/p:  
> {“contracts”:,“loading”:true}

---

<div class="post-metadata">

**Author:** ![Gary\_Verhaegen](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/gary_verhaegen/32/81_2.png) [@Gary\_Verhaegen](https://forum.canton.network/u/Gary_Verhaegen)\
**Post date:** [September 13, 2021, 9:09am UTC](https://forum.canton.network/t/bond-trading-ts-what-is-the-type/3100/8 "2021-09-13T09:09:08Z")

</div>

Are you logged in as the same party? Is there any chance you might have mixed up the package IDs?

That latter can occur if you have recompiled the DAR file without restarting the sandbox. Then the sandbox would have two versions of Bond, one with 10 active contracts and one with 0, and the UI code would be querying the second one.

---

<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:** [September 13, 2021, 9:11am UTC](https://forum.canton.network/t/bond-trading-ts-what-is-the-type/3100/9 "2021-09-13T09:11:48Z")

</div>

The data hasn’t finished loading yet, that’s why you get `loading: true`. Once it has finished loading, the number of contracts should match up (assuming you didn’t mix up parties or package ids).

---

<div class="post-metadata">

**Author:** ![Hem-M](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/hem-m/32/2044_2.png) [@Hem-M](https://forum.canton.network/u/Hem-M)\
**Post date:** [September 13, 2021, 11:50am UTC](https://forum.canton.network/t/bond-trading-ts-what-is-the-type/3100/10 "2021-09-13T11:50:17Z")

</div>

Checked for the correction you both have mentioned @Gary_Verhaegen@cocreature .

> [@Gary\_Verhaegen](#):
>
> Are you logged in as the same party?

I am modifying “daml-ui-template” and yes i have logged in as same party.

Is their a provision to query with party as parameter? if not how does the query know just with template what party is accessing it?

> [@Gary\_Verhaegen](#):
>
> Is there any chance you might have mixed up the package IDs?

I created all fresh again.

Still the resulting contract array is empty.

> [@cocreature](#):
>
> The data hasn’t finished loading yet, that’s why you get `loading: true` .

```haskell
const { contracts, loading } = useQuery(Bond); //with this we get all contracts associated with Bond template right?
if (!loading) {
    alert(JSON.stringify(contracts));
 }

```

The alert does not hit.

In the navigator based screen under “template” tab I see **Template Bond:Bond@a47bd7215c9a7a019f4cf03b9c95e501407c0c21515032846ceb37c5f8f086fa** for every parties and same shows up hovering on import statement in IDE.

---

<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:** [September 13, 2021, 11:54am UTC](https://forum.canton.network/t/bond-trading-ts-what-is-the-type/3100/11 "2021-09-13T11:54:22Z")

</div>

How are you using this? `useQuery` is internally based on `useEffect` so it’s intended to be used as a hook in a react component.

---

<div class="post-metadata">

**Author:** ![Gary\_Verhaegen](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/gary_verhaegen/32/81_2.png) [@Gary\_Verhaegen](https://forum.canton.network/u/Gary_Verhaegen)\
**Post date:** [September 13, 2021, 11:57am UTC](https://forum.canton.network/t/bond-trading-ts-what-is-the-type/3100/12 "2021-09-13T11:57:30Z")

</div>

> [@Hem-M](#):
>
> Is their a provision to query with party as parameter? if not how does the query know just with template what party is accessing it?

`useQuery` should only work within the context of a React component somehow nested within a `DamlLedger` component, and _that_ sets the party id (as a magic “ambient” value).
