{"id":"motoko","title":"Motoko","content":"Motoko is a programming language specifically designed for developing applications on the Internet Computer [blockchain](https://iq.wiki/wiki/blockchain) platform. It provides a type-safe and actor-based approach to building decentralized applications (dApps) with built-in support for the Internet Computer's unique features and capabilities. As an open-source project developed and maintained by the DFINITY [Foundation](https://iq.wiki/wiki/foundation), Motoko aims to simplify the creation of robust and scalable canister smart contracts [[2]](#cite-id-2y3OuyARi3).\n\n## History and Motivation\n\nMotoko was created by DFINITY to provide a purpose-built language for the Internet Computer, streamlining the development of canister smart contracts. The primary motivation behind its creation was to offer a high-level language that is both [safe](https://iq.wiki/wiki/safe) and easy to use, abstracting away many of the complexities of distributed systems programming. The language was designed from the ground up with several key goals in mind [[3]](#cite-id-I9cxDN279s):\n- **Simplicity and Familiarity**: To make development accessible to a broad range of programmers, Motoko incorporates a simple design and a syntax that is familiar to those with experience in modern languages like JavaScript, Java, C#, and Swift.\n- **Safety and Security**: As a language for smart contracts, security is paramount. Motoko is statically typed, which helps catch errors at compile-time rather than at runtime. It also features \"safety by default\" principles, such as overflow-checked arithmetic, immutable local variables by default, atomic concurrent execution, and the absence of null values to prevent [common](https://iq.wiki/wiki/common) security vulnerabilities [[3]](#cite-id-I9cxDN279s).\n- **Native Actor Model Support**: The language provides convenient, first-class support for the actor model, which aligns directly with the Internet Computer's canister-based architecture of isolated, stateful components.\n- **Seamless Integration**: Motoko was designed to be a perfect fit for the underlying WebAssembly (Wasm) runtime and the Internet Computer's execution model, with built-in features for asynchronous messaging, state persistence, and inter-canister communication.\n\nThese foundational goals have guided Motoko's evolution, positioning it as the primary, officially supported language for building on the Internet Computer.\n\n## Language Design and Philosophy\n\nMotoko's design philosophy centers around providing a [safe](https://iq.wiki/wiki/safe), expressive, and efficient language for Internet Computer development. The syntax draws inspiration from a wide array of modern programming languages, including Java, C#, JavaScript, Swift, Pony, ML, and Haskell, making it accessible to developers from various backgrounds. The compiler is written in OCaml, and its small runtime system, which primarily implements a garbage collector, is written in C and Rust [[3]](#cite-id-I9cxDN279s).\n\nThe language uses a declarative approach where possible, allowing developers to express what they want to accomplish rather than specifying exact implementation details. This is particularly evident in Motoko's type system, which supports type inference to reduce verbosity while maintaining type safety. Key design points include:\n- **Object-based Structure**: Motoko is fundamentally object-based, where core constructs like actors, classes, and modules are implemented as closures.\n- **Structural Typing**: It employs a structural type system, which focuses on the shape or structure of data rather than explicit name-based declarations. This is complemented by support for simple generics and subtyping.\n- **Asynchronous Programming**: The language features native `async` and `await` constructs for direct-style programming of asynchronous messaging, which is essential for inter-canister communication on the Internet Computer. The compiler implements this via a Continuation Passing Style (CPS) transformation, turning each `await` into a separate Wasm function [[3]](#cite-id-I9cxDN279s).\n- **Numeric Safety**: All number types have built-in overflow checking, and conversions between different numeric types must be explicit, reducing the risk of subtle bugs.\n\nOne of Motoko's distinguishing characteristics is its first-class support for the actor model, which aligns with the Internet Computer's architecture. An actor is a special kind of object that encapsulates its own state and communicates with other actors through asynchronous messages:\n\n```motoko\nactor Counter {\n  var count = 0;\n  \n  public func increment() : async Nat {\n    count += 1;\n    return count;\n  }\n  \n}\n```\n\nThis example demonstrates how actors in Motoko encapsulate state (the `count` variable) and expose functionality through public methods that can be called asynchronously from other canisters or from the frontend.\n\n## Key Features\n\nMotoko offers several distinctive features that make it suitable for Internet Computer development:\n- **Actor-based programming model**: Actors in Motoko represent the fundamental unit of computation and state isolation, aligning with the Internet Computer's canister model\n- **Static typing**: The language employs a strong type system that helps catch errors during compilation rather than at runtime\n- **Pattern matching**: Motoko supports sophisticated pattern matching for data extraction and control [flow](https://iq.wiki/wiki/flow)\n- **Automatic memory management**: The language handles memory allocation and deallocation through garbage collection\n- **Async/await**: Built-in support for asynchronous programming with async/await syntax\n\n### Orthogonal Persistence\n\nA cornerstone feature of Motoko is its approach to state management, which simplifies development by automatically persisting program state [across](https://iq.wiki/wiki/across) canister upgrades. This concept, known as orthogonal persistence, means developers do not need to write code to save data to external databases or files. The Internet Computer platform transparently preserves the state by monitoring the Wasm module's memory and persisting any modified pages between message invocations [[3]](#cite-id-I9cxDN279s). This has evolved into an advanced implementation called **Enhanced Orthogonal Persistence**.\n\nThis enhanced model combines two key technologies:\n1. **Stable Heap**: The program's main memory (the heap) is persisted directly [across](https://iq.wiki/wiki/across) canister upgrades, eliminating the need for developers to manually serialize and deserialize data to and from [stable](https://iq.wiki/wiki/stable) memory.\n2. **64-bit Heap**: The main memory is extended to a 64-bit address space, allowing canisters to manage vast amounts of data and scale beyond the limitations of traditional 32-bit WebAssembly.\n\nThis design offers significant advantages in performance and simplicity, as new program versions can resume directly from the existing memory state. To ensure safety during upgrades, Motoko performs a fast memory compatibility check. The compiler generates a type descriptor for all [stable](https://iq.wiki/wiki/stable) types, which is stored in persistent metadata. During an upgrade, the new program's type descriptor is compared against the old one, and the upgrade is only permitted if the changes are compatible (e.g., adding a new field to an actor but not removing one from an object). This mechanism provides a robust safety net against data corruption during software updates.\n\n### Advanced Features\n\nAs Motoko matures, it has incorporated more advanced features to improve code organization and expressiveness:\n- **Mixins**: This feature allows developers to define parts of an actor in a separate file and then include them in a main actor. Mixins can be parameterized, and their public definitions become part of the including actor's interface. This promotes code reuse and modularity, as [common](https://iq.wiki/wiki/common) functionalities can be abstracted into mixins and shared [across](https://iq.wiki/wiki/across) multiple canisters.\n- **Implicit Arguments**: To reduce boilerplate, Motoko supports implicit arguments. Function or class parameters can be declared as `implicit`, allowing them to be omitted at call sites. The compiler will then attempt to unambiguously resolve the missing argument from a declaration with a matching name and type in the current scope. This is particularly useful for passing [common](https://iq.wiki/wiki/common) context or configuration without cluttering function calls.\n\n## Integration with Internet Computer\n\nMotoko was specifically designed to work seamlessly with the Internet Computer protocol. It provides native abstractions for Internet Computer concepts such as:\n- **Canisters**: Motoko actors compile directly to Internet Computer canisters\n- **Update and query calls**: The language distinguishes between state-modifying \"update\" calls and read-only \"query\" calls using the `public func` and `public query func` keywords, respectively\n- **Cycles**: Built-in support for handling cycles, the computational resource tokens of the Internet Computer\n- **Inter-canister calls**: First-class support for communication between canisters via the `async`/`await` syntax\n- **Identities and Principals**: Native handling of the `Principal` type for identity and authentication within the ecosystem [[4]](#cite-id-WUHkFLcgOJ).\n- **System APIs**: Direct access to low-level IC functionality, including timers for scheduling future actions, certified variables for tamper-proof data, and access to the platform's secure cryptographic randomness [[4]](#cite-id-WUHkFLcgOJ).\n\nThe tight integration with the platform allows developers to [leverage](https://iq.wiki/wiki/leverage) the Internet Computer's capabilities without having to write extensive boilerplate code or manage low-level details.\n\n## Ecosystem and Tooling\n\nThe primary development environment for Motoko is the DFINITY Canister SDK, also known as the DFINITY Software Development Kit (SDK). This toolkit includes:\n- **Motoko compiler**: Translates Motoko code into WebAssembly modules that can run on the Internet Computer\n- **dfx command-line tool**: Provides utilities for creating, building, deploying, and managing Internet Computer applications\n- **Candid interface description language**: Facilitates interoperability between canisters written in different languages\n\nBeyond the core SDK, the ecosystem includes a rich set of tools and integrations to support the development lifecycle:\n\n#### Editor and Language Support\n- **VS Code Extension**: An official extension for Visual Studio Code provides syntax highlighting, code completion, and other language-aware features.\n\n#### Package Management\n- **Vessel**: The original package manager for Motoko projects, used to manage dependencies.\n- **MOPS**: A community-developed package manager hosted on the IC, offering an alternative for discovering and managing Motoko libraries.\n\nA notable package available through the ecosystem is the MCP Motoko SDK. This software development kit, available on the MOPS package manager, is designed for building servers compliant with the Model Context Protocol (MCP) on the Internet Computer. It provides developers with a comprehensive set of tools to handle low-level details of the MCP specification, such as routing, authentication, and connection management, allowing them to focus on application logic [[1]](#cite-id-neA9JGi3SR).\n\n#### Online Development Tools\n- **ICP Ninja**: An online platform and IDE for authoring, deploying, and sharing Motoko canisters directly in the browser [[2]](#cite-id-2y3OuyARi3).\n- **Motoko Playground**: A web-based IDE for experimenting with Motoko code snippets. It has been deprecated in favor of newer, more powerful online IDEs like ICP Ninja.\n\n#### Code Integration\n- **embed-motoko**: A tool for creating executable Motoko code snippets that can be embedded directly into websites.\n- **node-motoko**: Provides bindings for running and interacting with Motoko code from browser and Node.js environments.\n\n## Standard Library\n\nMotoko comes with a standard library that provides [common](https://iq.wiki/wiki/common) data structures and utilities. The library is undergoing a significant evolution, with a transition from the legacy `motoko-base` package to the next-generation `motoko-core` package. This migration reflects the ongoing effort to build a more robust and feature-rich set of core functionalities for the language [[2]](#cite-id-2y3OuyARi3). Key modules in the base library include:\n- **Base library**: Includes fundamental types and functions for working with primitives (`Nat`, `Int`, `Text`), arrays, text, iterators, and more [[4]](#cite-id-WUHkFLcgOJ).\n- **Collections**: Provides implementations of [common](https://iq.wiki/wiki/common) data structures like `HashMap`, `RBTree` (Red-Black Tree), `List`, and `Buffer` [[4]](#cite-id-WUHkFLcgOJ).\n- **Time**: Utilities for working with time values and durations.\n- **Debug**: Functions for debugging and logging during development.\n\nThe standard library continues to evolve as the Motoko ecosystem grows, with new modules being added to address [common](https://iq.wiki/wiki/common) development needs.\n\n## Community and Contribution\n\nThe Motoko community has developed a wide range of resources to support developers. These include educational platforms, curated lists of tools, and starter templates to accelerate development. Key community hubs include the official ICP Developer Forum and the ICP Developer Discord server [[2]](#cite-id-2y3OuyARi3).\n- **Awesome Motoko**: A community-curated list of Motoko resources, libraries, tools, and example projects.\n- **Blocks**: An online low-code editor designed for Motoko development.\n- **MOPS**: A Motoko package manager that is hosted on the Internet Computer.\n- **Motoko Bootcamp**: An educational program with a dedicated YouTube channel for learning Motoko.\n- **Motoko Library Starter Template**: A repository template to help developers create new Motoko libraries.\n\nThese community-driven initiatives provide valuable support for both new and experienced developers in the Motoko ecosystem.\n\n### Contributing to Motoko\n\nAs an open-source project, Motoko welcomes contributions from the community. The official GitHub repository provides detailed guidelines for developers who wish to contribute to the language, compiler, or surrounding tooling. Resources for contributors include a `CONTRIBUTING.md` file outlining the development process, a `CODE_OF_CONDUCT.md` to ensure a welcoming community, and a `Building.md` file with instructions for setting up the development environment and building the project from source.\n\n> As an open-source project, [Motoko](https://iq.wiki/wiki/motoko) welcomes contributions from the community. The official GitHub repository provides detailed guidelines for developers who wish to contribute to the language, compiler, or surrounding tooling. Resources for contributors include a CONTRIBUTING.md file outlining the development process, a CODE_OF_CONDUCT.md to ensure a welcoming community, and a Building.md file with instructions for setting up the development environment and building the project from source.\n\n## Comparison with Other Languages\n\nWhile Motoko is the primary language for Internet Computer development, it's not the only option. The platform's use of WebAssembly as a compilation target allows for a polyglot environment. Other languages supported include:\n- **Rust**: Offers more low-level control, manual memory management, and potentially better performance for certain use cases. It is a popular choice for systems-level programming and performance-critical canisters.\n- **JavaScript/TypeScript**: Through tools like Azle, web developers can [leverage](https://iq.wiki/wiki/leverage) their existing skills and the vast JavaScript ecosystem to build canisters.\n- **Python**: Via SDKs like Kybra that enable Python development for the Internet Computer, making it accessible to data scientists and developers familiar with the Python ecosystem.\n\nCompared to these alternatives, Motoko offers the advantage of being purpose-built for the Internet Computer. Its features, such as the actor model and orthogonal persistence, directly map to platform concepts, often resulting in more concise and idiomatic code for canister development. However, the language faces adoption challenges due to its tight coupling with the Internet Computer. Its compiler is deeply dependent on the IC's specific system API, making it difficult to port to other WebAssembly-based platforms and creating a higher barrier to entry for developers who may want to apply their skills outside the IC ecosystem. This has led some development teams, including some at DFINITY, to prefer the more mature and portable Rust ecosystem for certain projects [[5]](#cite-id-b6RWeUAfNk). The choice of language often depends on the specific requirements of the project and the background of the development team.","summary":"Motoko is a programming language designed for the Internet Computer, offering features like actor-based concurrency and type safety, tailored for building scala...","images":[{"id":"QmPGr6CynqADqoy1KncVMC8bz1Uaw381RRYJDiTDyLZcn8","type":"image/jpeg, image/png"}],"categories":[{"id":"dapps","title":"Dapps"}],"tags":[{"id":"Ethereum"},{"id":"Protocols"},{"id":"Blockchains"},{"id":"Developers"},{"id":"Polkadot"}],"media":[{"id":"QmPGr6CynqADqoy1KncVMC8bz1Uaw381RRYJDiTDyLZcn8","size":null,"name":null,"type":"GALLERY","source":"IPFS_IMG"},{"id":"QmXdAviauPHkVv3MZyCFhx8yJUCftqFMnqx2ZmMdojHFJS","size":null,"name":null,"type":"GALLERY","source":"IPFS_IMG"},{"id":"QmWE2SBpLaTBR6CHqvy3WMjtrzWdMSQmpiLJ7xggYhGAni","size":null,"name":null,"type":"GALLERY","source":"IPFS_IMG"},{"id":"QmeXVRw1d79tErKQj7ZFEnQ76Fmkt6roAUJLJjuwvnK5kr","size":null,"name":null,"type":"GALLERY","source":"IPFS_IMG"},{"id":"QmRJ4YnkyosKLYRzbwM2to8FW8LCSQAbxPd3e33rfQkDPv","size":null,"name":null,"type":"GALLERY","source":"IPFS_IMG"}],"metadata":[{"id":"references","value":"[{\"id\":\"neA9JGi3SR\",\"url\":\"https://mops.one/mcp-motoko-sdk\",\"description\":\"mcp-motoko-sdk on MOPS\",\"timestamp\":1760112065972},{\"id\":\"2y3OuyARi3\",\"url\":\"https://internetcomputer.org/docs/motoko/home\",\"description\":\"Motoko language documentation\",\"timestamp\":1761816973627},{\"id\":\"I9cxDN279s\",\"url\":\"https://stackoverflow.blog/2020/08/24/motoko-the-language-that-turns-the-web-into-a-computer/\",\"description\":\"Stack Overflow blog post on Motoko\",\"timestamp\":1761816973627},{\"id\":\"WUHkFLcgOJ\",\"url\":\"https://motoko-book.dev/\",\"description\":\"The Motoko Programming Language Book\",\"timestamp\":1761816973627},{\"id\":\"b6RWeUAfNk\",\"url\":\"https://forum.dfinity.org/t/the-future-of-motoko-and-concerns/18975\",\"description\":\"IC Developer Forum discussion on Motoko's future\",\"timestamp\":1761816973627}]"},{"id":"previous_cid","value":"QmdAA9Xd6tHk35ZyZo7Na2tVYWcFr2Mzv8KGGopPVSuDC6"},{"id":"previous_cid","value":"QmdAA9Xd6tHk35ZyZo7Na2tVYWcFr2Mzv8KGGopPVSuDC6"},{"id":"commit-message","value":""},{"id":"previous_cid","value":"QmdAA9Xd6tHk35ZyZo7Na2tVYWcFr2Mzv8KGGopPVSuDC6"}],"events":[{"id":"3f8c1a3a-88f2-4ba6-8bf0-2c0ac35d05e6","date":"2025-01-01","title":"Docs creation","type":"CREATED","description":"Docs creation description","link":"","multiDateStart":null,"multiDateEnd":null,"continent":null,"country":null},{"id":"24ee0628-5524-4be9-8773-2e479b861bd5","date":"2025-10","title":"milestone update","type":"DEFAULT","description":"milestone update description","link":"https://test.ai","multiDateStart":null,"multiDateEnd":null,"continent":null,"country":null}],"user":{"id":"0x5456afEA3aa035088Fe1F9Aa36509B320360a89e"},"author":{"id":"0x8af7a19a26d8fbc48defb35aefb15ec8c407f889"},"language":"en","version":1,"linkedWikis":{"blockchains":["solana-sol"],"founders":[],"speakers":[]}}