# Source to get .did file from any canister

**URL:** <https://forum.dfinity.org/t/source-to-get-did-file-from-any-canister/27294>\
**Category:** Developers\
**Tags:** Discussing, TypeScript\
**Created:** [February 5, 2024, 3:49am UTC](https://forum.dfinity.org/t/source-to-get-did-file-from-any-canister/27294 "2024-02-05T03:49:10Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![b3hr4d](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/b3hr4d/32/9755_2.png) [@b3hr4d](https://forum.dfinity.org/u/b3hr4d)\
**Post date:** [June 28, 2024, 6:29pm UTC](https://forum.dfinity.org/t/source-to-get-did-file-from-any-canister/27294/7 "2024-06-28T18:29:36Z")

</div>

> [@jaesharma](#):
>
> Can we fetch the candid of a canister using JavaScript?

I would suggest using `@ic-reactor`, a library I’m currently developing. You can easily use the [CandidAdapter](https://b3pay.github.io/ic-reactor/functions/core.createCandidAdapter.html) feature to get the candid definition as an `idlFactory`, which can be used directly to create an actor:

```typescript
// adapter.ts
import { createAgentManager, createCandidAdapter } from "@ic-reactor/core";

export const agentManager = createAgentManager({ withProcessEnv: true });

export const adapter = createCandidAdapter({ agentManager });

export async function getCandidDefinition(canisterId: string) {
  return adapter.getCandidDefinition(canisterId);
}

```

> [@jaesharma](#):
>
> To convert DID into JS/TS, I found that we can get it from this canister:

This approach is similar to the one used by [candid-ui](https://github.com/dfinity/candid/tree/master/tools/ui).

> [@jaesharma](#):
>
> Do we have any other offline solutions?

Yes, there is also an offline solution using the wasm mentioned by @sea-snake. You just need to install:

```shell
npm install @ic-reactor/parser

```

Then, initialize the wasm parser after creating the `CandidAdapter`:

```typescript
adapter.initializeParser();

```

Additionally, if you are using React, you might want to try [@ic-reactor/react](https://forum.dfinity.org/t/introduction-ic-reactor-react-for-react-developers/27930/1). It has a built-in adapting actor feature that only requires you to specify the `canisterId` to interact with it!

I have developed this library and it is used extensively in the creation of B3Forge. Please also give a shot to the [B3Forge/playground](https://sehgq-cqaaa-aaaap-ahc4q-cai.icp0.io/playground). As you can see, it does not make a call to convert candid into JavaScript.

---

_[View the full topic](https://forum.dfinity.org/t/source-to-get-did-file-from-any-canister/27294)._
