Skip to content

Latest commit

 

History

History
111 lines (84 loc) · 3.23 KB

2005.md

File metadata and controls

111 lines (84 loc) · 3.23 KB

🏠 HOME

Building a Smart Contract using Ask! (TypeScript)

What is Ask! ?

It's AssemblyScript-based framework. AssemblyScript is a TypeScript-like language for WebAssembly. Ask! allows writing smart contracts in a familiar syntax while compiling to WebAssembly (WASM) for Polkadot compatibility.

Ink!! vs. Ask!

Aspect Ink! (Rust) Ask! (TypeScript)
Language Rust (statically typed, systems) TypeScript (JS superset, dynamic)
Familiarity Steeper learning curve Easier for JS/TS developers
Safety Compile-time guarantees Runtime checks (no borrow checker)
Adoption Default choice Experimental (discontinued?)
Use Case Production-grade Prototyping, JS/TS devs
Virtual Machine Any Wasm VM Any Wasm VM
Encoding Wasm Wasm
Language Rust AssemblyScript
Overflow Protection Enabled by default None
Constructor Functions Multiple Multiple
Versioning Semantic Semantic
Has Metadata? Yes Yes
Multi-File Project Planned Yes
Storage Entries Variable Variable
Supported Types Docs Docs
Has Interfaces? Yes (Rust Traits) Yes

A simple example, the Flipper

/* eslint-disable @typescript-eslint/no-inferrable-types */
import { env, Pack } from "ask-lang";

@event({ id: 1 })
export class FlipEvent {
    flag: bool;

    constructor(flag: bool) {
        this.flag = flag;
    }
}

@spreadLayout
@packedLayout
export class Flipper {
    flag: bool;
    constructor(flag: bool = false) {
        this.flag = flag;
    }
}

@contract
export class Contract {
    _data: Pack<Flipper>;

    constructor() {
        this._data = instantiate<Pack<Flipper>>(new Flipper(false));
    }

    get data(): Flipper {
        return this._data.unwrap();
    }

    set data(data: Flipper) {
        this._data = new Pack(data);
    }

    @constructor()
    default(flag: bool): void {
        this.data.flag = flag;
    }

    @message({ mutates: true })
    flip(): void {
        this.data.flag = !this.data.flag;
        let event = new FlipEvent(this.data.flag);
        // @ts-ignore
        env().emitEvent(event);
    }

    @message()
    get(): bool {
        return this.data.flag;
    }
}

Download from ask-template and build it

yarn build flipper.ts

After building we tried to upload the wasm on test net but it returns the error This contract file is not in a valid format.


Why Ask! still has potential

  • Lower Barrier: TypeScript devs can onboard to Polkadot faster.
  • Wasm Backend: Compiles to the same target as ink!, so theoretically interoperable.

Proceed with Caution:

While Ask! offers a friendlier syntax, its uncertain future and lack of tooling make it risky for mission-critical projects.

🏠 HOME