MaxCodeLen

Constant v334 → current u32

Limits contract code size for performance and storage .

Current Value

131072
Relevant for: developers

The Big Picture

WASM code can't be arbitrarily large. This limit protects against oversized contracts that would slow compilation or consume excessive storage. Optimize or split large contracts.

From Chain Metadata

The maximum length of a contract code in bytes. The value should be chosen carefully taking into the account the overall memory limit your runtime has, as well as the [maximum allowed callstack depth](#associatedtype.CallStack). Look into the `integrity_test()` for some insights.

Use Cases

  • Check if your contract fits size limits
  • Plan contract architecture for large applications

Code Examples

import { ApiPromise, WsProvider } from "@polkadot/api";
import { stringCamelCase } from "@polkadot/util";

const provider = new WsProvider("wss://entrypoint-finney.opentensor.ai:443");
const api = await ApiPromise.create({ provider });

// Query MaxCodeLen constant
const value = api.consts[stringCamelCase("Contracts")][stringCamelCase("MaxCodeLen")];
console.log("MaxCodeLen:", value.toHuman());

Type Information

Type
u32
Byte Size
4 bytes
Encoding
fixed
Raw Hex
0x00000200

Runtime Info

Pallet
Contracts
First Version
v334
Latest Version
v334
Current Runtime
v393