# How to fetch canister metadata on-chain?

**URL:** <https://forum.dfinity.org/t/how-to-fetch-canister-metadata-on-chain/22543>\
**Category:** Motoko\
**Created:** [September 4, 2023, 3:35pm UTC](https://forum.dfinity.org/t/how-to-fetch-canister-metadata-on-chain/22543 "2023-09-04T15:35:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ZenVoich](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/zenvoich/32/5969_2.png) [@ZenVoich](https://forum.dfinity.org/u/ZenVoich)\
**Post date:** [September 4, 2023, 3:35pm UTC](https://forum.dfinity.org/t/how-to-fetch-canister-metadata-on-chain/22543/1 "2023-09-04T15:35:12Z")

</div>

I want to get canister’s metadata sections such as `candid:service` and `motoko:compiler`.  
Can I access them on-chain from a Motoko canister? If not, is it possible via http outcalls to some endpoint?

---

<div class="post-metadata">

**Author:** ![lwshang](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/lwshang/32/3394_2.png) [@lwshang](https://forum.dfinity.org/u/lwshang)\
**Post date:** [September 5, 2023, 7:36pm UTC](https://forum.dfinity.org/t/how-to-fetch-canister-metadata-on-chain/22543/2 "2023-09-05T19:36:48Z")

</div>

The [metadata](https://internetcomputer.org/docs/current/references/ic-interface-spec#state-tree-canister-information) is a component of the [system state tree](https://internetcomputer.org/docs/current/references/ic-interface-spec#state-tree).

Getting such information from IC normally involves read\_state, certification verification, parsing the state tree, looking for a path on the tree.

It is agents’ job to encapsulate such functionality with convenient API, e.g. `agent-rs`, `agent-js`. And agents are normally used outside canister code.

For Rust canisters, you may be able to use `agent-rs` to fetch canister metadata within a canister. I haven’t tried it before and can’t guarantee it will work.

I don’t know if it’s doable in Motoko.

---

<div class="post-metadata">

**Author:** ![chenyan](https://avatars.discourse-cdn.com/v4/letter/c/35a633/32.png) [@chenyan](https://forum.dfinity.org/u/chenyan)\
**Post date:** [September 5, 2023, 8:10pm UTC](https://forum.dfinity.org/t/how-to-fetch-canister-metadata-on-chain/22543/3 "2023-09-05T20:10:59Z")

</div>

Theoretically, it’s possible make an HTTP outcall using the IC HTTP interface: [The Internet Computer Interface Specification | Internet Computer](https://internetcomputer.org/docs/current/references/ic-interface-spec/#http-interface)

But I don’t know if we have libraries to parse and authenticate the state tree in Motoko. It’s best to refactor the code, so that we can fetch the metadata on the client side, rather than on the server side.

---

<div class="post-metadata">

**Author:** ![anon74414410](https://avatars.discourse-cdn.com/v4/letter/a/85f322/32.png) [@anon74414410](https://forum.dfinity.org/u/anon74414410)\
**Post date:** [September 5, 2023, 9:43pm UTC](https://forum.dfinity.org/t/how-to-fetch-canister-metadata-on-chain/22543/4 "2023-09-05T21:43:38Z")

</div>

It would be convenient if canister metadata was made available by extending the management canister API

---

<div class="post-metadata">

**Author:** ![ZenVoich](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/zenvoich/32/5969_2.png) [@ZenVoich](https://forum.dfinity.org/u/ZenVoich)\
**Post date:** [September 6, 2023, 8:11am UTC](https://forum.dfinity.org/t/how-to-fetch-canister-metadata-on-chain/22543/5 "2023-09-06T08:11:01Z")

</div>

Also would be nice to have on-chain access to canister’s wasm hash, controllers…

And list of all canisters)
