# Attempting to create a contract is sending the wrong templateId

**URL:** <https://forum.canton.network/t/attempting-to-create-a-contract-is-sending-the-wrong-templateid/1910>\
**Category:** App Development\
**Tags:** javascript\
**Created:** [January 8, 2021, 2:30pm UTC](https://forum.canton.network/t/attempting-to-create-a-contract-is-sending-the-wrong-templateid/1910 "2021-01-08T14:30:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![anthony](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/anthony/32/419_2.png) [@anthony](https://forum.canton.network/u/anthony)\
**Post date:** [January 8, 2021, 2:30pm UTC](https://forum.canton.network/t/attempting-to-create-a-contract-is-sending-the-wrong-templateid/1910/1 "2021-01-08T14:30:04Z")

</div>

I’m attempting to use the `@daml/ledger` library in vanilla JS (really Vue.js but doesn’t matter).

However when I submit the following request to the ledger I get an error.

```haskell
import Ledger from '@daml/ledger';
var ledger = new Ledger({token, ledgerUrl, reconnectThreshold: 1337});
var payload = {
  beer: {
  templateId: "Beer:Beer",
  giver: state.party,
  recipient: recipient
  }
};

try {
  await ledger.create("Beer:BeerProposal", payload);
}
catch (err) {
  console.log("Couldn't create contract " + err)
}

```

Error:

```haskell
{kind: "DecoderError", input: Array(2), at: "input[0].templateId", message: "expected "Beer:BeerProposal", got "5185bd6f731b53b…703cb9b62835b567f9631e08121fef:Beer:BeerProposal""}

```

I’m running local sandbox on Daml 1.8 and this appears to be a contractId included in the templateId. I’m not quite sure where it’s coming from though.

---

<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:** [January 8, 2021, 2:34pm UTC](https://forum.canton.network/t/attempting-to-create-a-contract-is-sending-the-wrong-templateid/1910/2 "2021-01-08T14:34:50Z")

</div>

`@daml/ledger` is really intended to be used with the JavaScript code generator. The first arguments to `ledger.create` is then the generated template. The code generator also works perfectly fine without React.

---

<div class="post-metadata">

**Author:** ![anthony](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/anthony/32/419_2.png) [@anthony](https://forum.canton.network/u/anthony)\
**Post date:** [January 8, 2021, 2:36pm UTC](https://forum.canton.network/t/attempting-to-create-a-contract-is-sending-the-wrong-templateid/1910/3 "2021-01-08T14:36:27Z")

</div>

I used the codegen but am a bit unclear about how to use it in my project. The docs say to look at how `@daml/react` is implemented and I have but I’m not familiar with TypeScript so…what am I missing here?

---

<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:** [January 8, 2021, 2:40pm UTC](https://forum.canton.network/t/attempting-to-create-a-contract-is-sending-the-wrong-templateid/1910/4 "2021-01-08T14:40:02Z")

</div>

The codegen generates something like `@daml.js/proj`. You can the import it as

```haskell
import * as proj from '@daml.js/proj'

```

The generated code will then include something like `proj.ModuleName.TemplateName`. This is what you pass in to `ledger.create`. So something like:

```haskell
ledger.create(proj.ModuleName.TemplateName, …)

```

You can see this put to use in DAVL’s [admin CLI](https://github.com/digital-asset/davl/blob/87108e894495893af4bba31d833b9a1443f131ba/admin-cli/src/index.ts#L66) which is run via NodeJS without any UI framework.

---

<div class="post-metadata">

**Author:** ![anthony](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/anthony/32/419_2.png) [@anthony](https://forum.canton.network/u/anthony)\
**Post date:** [January 8, 2021, 3:28pm UTC](https://forum.canton.network/t/attempting-to-create-a-contract-is-sending-the-wrong-templateid/1910/5 "2021-01-08T15:28:31Z")

</div>

Awesome, this + `yarn add ./daml.js/proj-version/` worked. Thanks!

---

<div class="post-metadata">

**Author:** ![lisandro\_iraguen](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/lisandro_iraguen/32/1102_2.png) [@lisandro\_iraguen](https://forum.canton.network/u/lisandro_iraguen)\
**Post date:** [June 4, 2021, 6:29pm UTC](https://forum.canton.network/t/attempting-to-create-a-contract-is-sending-the-wrong-templateid/1910/6 "2021-06-04T18:29:27Z")

</div>

Good day, I am tring to do the same but I got

> Couldn’t create contract TypeError: template.encode is not a function

when I run this line of code  
 ![image](https://canada1.discourse-cdn.com/flex028/uploads/daml/original/2X/c/cebb3685b47b33ed2e4193b9b5ce0fb848cdb08d.png)

I am using the CBDCv1 sample from here

> **[GitHub - digital-asset/blog-cbdc-examples](https://github.com/digital-asset/blog-cbdc-examples)**
>
> Contribute to digital-asset/blog-cbdc-examples development by creating an account on GitHub.

best regards

---

<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 4, 2021, 6:46pm UTC](https://forum.canton.network/t/attempting-to-create-a-contract-is-sending-the-wrong-templateid/1910/7 "2021-06-04T18:46:31Z")

</div>

Hi @paleiov, you should pass in the template which is `cdbc.CBDCv1.CBDC` not `cdbc.CBDCv1.CBDCTemplate`.

---

<div class="post-metadata">

**Author:** ![lisandro\_iraguen](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/lisandro_iraguen/32/1102_2.png) [@lisandro\_iraguen](https://forum.canton.network/u/lisandro_iraguen)\
**Post date:** [June 5, 2021, 6:46pm UTC](https://forum.canton.network/t/attempting-to-create-a-contract-is-sending-the-wrong-templateid/1910/8 "2021-06-05T18:46:14Z")

</div>

thanks again, it was an error in the smart contract itself \>D
