Naming requirements for canister methods

Do canister methods actually have any specific naming requirements? In the code, we seem to use strings, but are there any restrictions, such as minimum or maximum length, or any characters that are not allowed, etc.?

1 Like

There’s a restriction on the total length of the exported functions: their joint length must not exceed 20,000. Moreover, the name must be a valid UTF-8 string.

2 Likes

Interesting! Now I’m wondering how I would set up a Zod rule to validate the overall 20,000 length, but I’m going to leave it in the backlog for now :grinning_face_with_smiling_eyes:.

Really good to know—thanks, @mraszyk!

Is there a CLI tool that prints out how close a canister is to each of these limits below (from the provided link)?

  • The IC may reject WebAssembly modules that
    • declare more than 50,000 functions, or
    • declare more than 1,000 globals, or
    • declare more than 16 exported custom sections (the custom section names with prefix icp:), or
    • the number of all exported functions called canister_update <name>, canister_query <name>, or canister_composite_query <name> exceeds 1,000, or
    • the sum of <name> lengths in all exported functions called canister_update <name>, canister_query <name>, or canister_composite_query <name> exceeds 20,000, or
    • the total size of the custom sections (the sum of <name>lengths in their names icp:public <name> and icp:private <name> plus the sum of their content lengths) exceeds 1MiB.

I don’t know the answer, but reading your message made me think that those assertions related to sections would suit ic-wasm well (if not yet implemented).

That sounds like a challenge: Can you use an empty string as a canister method name? :wink:

Now I wish I could use a smiley for method names. :laughing:

1 Like