Patract Tutorial Series#1|Ask!Part 1 — wasm smart contract with TypeScript/AssemblyScript

What is Ask!

Why Ask!

  1. Being a variant of TypeScript makes it easy to compile to WebAssembly without learning a new language.
  2. AssemblyScript is the most popular language for WASM besides C/CPP/Rust.
  3. AssemblyScript targets WebAssembly’s feature set specifically, giving developers low-level control over their code.
  4. Integrates with the existing JS ecosystem — no heavy toolchains to set up. Simply npm install it!
  5. Small WASM size and good contract execution performance compared to Rust.

First Ask! project — Flipper

Setup Ask! env

mkdir flippercd flippernpx pl-ask-cli init
@contractclass Flipper {    @state flag: bool;    constructor() {    }    @constructor    default(initFlag: bool): void {        this.flag = initFlag;    }    @message    flip(): void {        const v = this.flag;this.flag = !v;}    @message({"mutates": false})    get(): bool {        return this.flag;    }}

Decorators

Compile the contract using ask-cli

metadata.json

Event

import {AccountId, msg, Event} from "ask-lang";@eventclass Flip extends Event {    from: AccountId;    flip_result: bool;    constructor(from: AccountId,  flip_result: bool) {      super();      this.from = from;      this.flip_result = flip_result;    }}
@messageflip(): void {    const v = this.flag;    this.flag = !v;    (new Flip(msg.sender, this.flag)).emit();}
"events": [  {    "name": "Flip",    "args": [      {        "indexed": false,        "type": {          "type": 3,          "displayName": [            "AccountId"          ]        },        "docs": [          ""        ],        "name": "from"        },        {          "indexed": false,          "type": {          "type": 1,          "displayName": [            "bool"          ]        },        "docs": [          ""        ],        "name": "flip_result"      }    ],    "docs": []  }],
@topic from: AccountId;
    {      "indexed": true,      "type": {        "type": 3,        "displayName": [          "AccountId"        ]      },      "docs": [        ""      ],      "name": "from"    },

About Patract Labs

--

--

Patract is providing solutions for the development of Parachains and DApps in the Wasm smart contract ecosystem of Polkadot.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Patract| Wasm Contract Open Platform

Patract is providing solutions for the development of Parachains and DApps in the Wasm smart contract ecosystem of Polkadot.