Important

The DFINITY Canister SDK is alpha software from our final development branch that will make it into production. Please be aware that at this time it is less developed than previously demonstrated prototypes and regularly check back to try new features.

Until the production release of the SDK, the Motoko language is under constant development and all features are subject to final security review.

The DFINITY Canister SDK will make it possible to easily build systems and services that run on the Internet Computer. Over time, many SDKs targeting canister development will become available. DFINITY’s Motoko language is being developed to provide a robust and productive platform for developers building next generation systems and services. Rust support is in the works…​

The Motoko compiler and language will soon become open source.

Enjoy!

The DFINITY Canister SDK can be used to create software systems and services that run on the Internet Computer. Over time, many different SDKs targeting canister development will be created by different organizations. The Motoko language is being developed by DFINITY to play well with the Internet Computer and provide a productive and robust platform for developers building next generation systems.

Highlights

Native canister support

actor Counter {
  var value = 0;
  public func inc() : async Nat {
    value += 1;
    return value;
  };
}

Motoko has native support for Internet Computer software canisters, which are expressed as actors, autonomous objects that encapsulate their state and communicate through asynchronous messages.

Code sequentially in direct style

actor Factorial {
  var last = 1;
  public func next() : async Nat {
    last *= (await Counter.inc());
    return last;
  }
}

On the Internet Computer, software canisters call into other canisters asynchronously, but Motoko enables you to program your systems sequentially in direct style. Asynchronous messages are function calls that return a future, and the await constructs allows chaining calls as if they were synchronous.

Modern type system

type Tree<T> = {
  #leaf : T;
  #branch : {left : Tree<T>; right : Tree<T>};
};

func iterTree<T>(tree : Tree<T>, f : T -> ()) {
  switch (tree) {
    case (#leaf(x)) { f(x) };
    case (#branch{left; right}) {
      iterTree<T>(left, f);
      iterTree<T>(right, f);
    };
  }
}

Motoko has been designed to be intuitive to those familiar with Javascript and other popular languages, but features a modern features such as sound structural types, generics, variant types, and checked pattern matching.

Autogenerated IDL files

service Counter : {
  inc : () -> (nat);
  reset : () -> ();
}

The SDK exports your interface definition, so other canisters, browser resident code and smart phone apps that have permission can call into your functions. The Motoko compiler can also read and write interface definition files, allowing Motoko to seamlessly interact with canisters programmed in other languages.

Orthogonal persistence

import Dict = "mo:dict";

actor Registry {
  type Id = Nat64;
  let dict = Dict<Id>();
  public func register(name : Text, id : Id) {
    dict.insert<Id>(name, id);
  };
  public func lookup(name : Text, id : Id) : async ?Id {
    dict.lookup<Id>(name);
  };
}

The Internet Computer persists the memory pages in which your canister runs. Thus the state of an actor and all its memory data structures survive indefinitely, they do not need to be “saved” explicitly. Motoko provides numerous features to help you leverage this environment, including language features that allow your heap to self-migrate when you upgrade the software of a canister.

Motoko provides many other cool features, including deep support for WebAssembly that allows modules written in other languages to be linked into your canisters. We are also working on adding Rust support to the SDK.

Keep checking back for updates.