# Read+write canister wasm module metadata

**URL:** <https://forum.dfinity.org/t/read-write-canister-wasm-module-metadata/27066>\
**Category:** Developers\
**Created:** [January 28, 2024, 7:57pm UTC](https://forum.dfinity.org/t/read-write-canister-wasm-module-metadata/27066 "2024-01-28T19:57:20Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![peterparker](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@peterparker](https://forum.dfinity.org/u/peterparker)\
**Post date:** [January 28, 2024, 7:57pm UTC](https://forum.dfinity.org/t/read-write-canister-wasm-module-metadata/27066/1 "2024-01-28T19:57:20Z")

</div>

I’m having a look at the README of [ic-wasm](https://github.com/dfinity/ic-wasm).

Do I understand correctly that I can add or overwrite any kind of custom metadata to a wasm module?

Like:

```auto
$ ic-wasm input.wasm -o output.wasm metadata hello:world -d "that's my metadata info" -v public

```

If so, once deployed on a local replica or mainnet, is there a way to read this metadata from a dapp (frontend), e.g. using agent-js?

---

<div class="post-metadata">

**Author:** ![aterga](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/aterga/32/4143_2.png) [@aterga](https://forum.dfinity.org/u/aterga)\
**Post date:** [January 28, 2024, 8:22pm UTC](https://forum.dfinity.org/t/read-write-canister-wasm-module-metadata/27066/2 "2024-01-28T20:22:29Z")

</div>

Yes, the metadata section can be customized with arbitrary sub-sections (private or public); beyond that, I’m not aware of any standard being enforced for which metadata subsections. (Some tools, e.g., DFX, seem to be creating their own metadata standard within a particular metadata subsection, e.g. `icp:public dfx`, followed by a string in JSON notation).

Speaking of DFX, it has a nice feature for reading the metadata section of a deployed canister, e.g., the following `git_commit_id` metadata sub-section:

```auto
dfx canister --network ic metadata $CANISTER git_commit_id

```

I’m pretty sure one could read the metadata via an agent library, but I’ve not tried that with agent-js.

Note that a matadata section of a compressed (gzipped) WASMs is itself not compressed.

A great metadata entry that I would recommend to add to any canister is `candid:service`, pointing to the canister’s Candid definition.

---

<div class="post-metadata">

**Author:** ![peterparker](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@peterparker](https://forum.dfinity.org/u/peterparker)\
**Post date:** [January 28, 2024, 8:30pm UTC](https://forum.dfinity.org/t/read-write-canister-wasm-module-metadata/27066/3 "2024-01-28T20:30:50Z")

</div>

> [@aterga](#):
>
> Yes, the metadata section can be customized with arbitrary sub-sections

Thanks for the answer and confirmation. Is there is any limitation such as size or types? Any specification available somewhere?

> [@aterga](#):
>
> I’m pretty sure one could read the metadata via an agent library, but I’ve not tried that with agent-js.

That’s the second important aspect of my question. I would be really curious to know about this as it would be an interesting reason why I would foreseen the use of those metadata sections.

---

<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:** [January 28, 2024, 8:47pm UTC](https://forum.dfinity.org/t/read-write-canister-wasm-module-metadata/27066/4 "2024-01-28T20:47:25Z")

</div>

You can define at most 16 metadata sections, and the combine content size cannot exceed 1M. See [interface-spec/spec/index.md at master · dfinity/interface-spec · GitHub](https://github.com/dfinity/interface-spec/blob/master/spec/index.md#webassembly-module-requirements-system-api-module).

agent-js example: [agent-js/e2e/node/basic/canisterStatus.test.ts at main · dfinity/agent-js · GitHub](https://github.com/dfinity/agent-js/blob/main/e2e/node/basic/canisterStatus.test.ts)

---

<div class="post-metadata">

**Author:** ![peterparker](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@peterparker](https://forum.dfinity.org/u/peterparker)\
**Post date:** [January 28, 2024, 9:01pm UTC](https://forum.dfinity.org/t/read-write-canister-wasm-module-metadata/27066/5 "2024-01-28T21:01:34Z")

</div>

> [@chenyan](#):
>
> You can define at most 16 metadata sections

That’s great, thanks for the answer and links.

@aterga mentionned that dfx seem to be creating particular metadata, so it’s 16 counting does already used by dfx or it’s minus those? if minus, do we know how many sections dfx is using?

> [@chenyan](#):
>
> agent-js example:

Do I get it right, the argument `paths` should then be used as the key?

e.g. given a public metadata “hello:world”

```auto
$ ic-wasm input.wasm -o output.wasm metadata hello:world -d "that's my value" -v public

```

I would query it as following:

```auto
const request = await CanisterStatus.request({
      canisterId: Principal.from(counterObj.canisterId),
      agent,
      paths: ['hello:world'],
    });

```

Correct?

---

<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:** [January 28, 2024, 9:12pm UTC](https://forum.dfinity.org/t/read-write-canister-wasm-module-metadata/27066/6 "2024-01-28T21:12:40Z")

</div>

Yes, metadata made by dfx are counted towards the 16 limit. I think you can opt-out this behavior in `dfx.json`. I think dfx only add 2-3 metadata sections. You can check it by running `ic-wasm a.wasm metadata` to list all metadata in a wasm binary.

> Do I get it right, the argument `paths` should then be used as the key?

Most likely, but better to check with the documentation. There are some options to config the output type, here is another example: [candid/tools/ui/src/candid.ts at master · dfinity/candid · GitHub](https://github.com/dfinity/candid/blob/master/tools/ui/src/candid.ts#L124)

---

<div class="post-metadata">

**Author:** ![peterparker](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@peterparker](https://forum.dfinity.org/u/peterparker)\
**Post date:** [January 28, 2024, 9:15pm UTC](https://forum.dfinity.org/t/read-write-canister-wasm-module-metadata/27066/7 "2024-01-28T21:15:52Z")

</div>

Thanks for the details, looks promising!

---

<div class="post-metadata">

**Author:** ![Vivienne](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/vivienne/32/29170_2.png) [@Vivienne](https://forum.dfinity.org/u/Vivienne)\
**Post date:** [January 29, 2024, 12:12pm UTC](https://forum.dfinity.org/t/read-write-canister-wasm-module-metadata/27066/8 "2024-01-29T12:12:48Z")

</div>

You can also configure metadata in dfx.json. Here’s the documentation: [sdk/docs/concepts/canister-metadata.md at master · dfinity/sdk · GitHub](https://github.com/dfinity/sdk/blob/master/docs/concepts/canister-metadata.md)
