ask! Development

⚠️ Production Warning ask! eDSL currently has several limitations and issues being actively addressed. It is not recommended for production environments. Consider using ink! for production contracts.

View known issues

Introduction

ask! is a framework that enables AssemblyScript developers to write Wasm smart contracts for pallet-contracts. With TypeScript-like syntax, it makes smart contract development accessible to JavaScript/TypeScript developers.

💡 Project Status ask! is a Polkadot treasury funded project currently under active development.

Prerequisites

  • Basic understanding of TypeScript/JavaScript

  • Familiarity with package managers (yarn/npm)

Environment Setup

1. Install Yarn

npm install --global yarn

2. Clone Template Repository

git clone https://github.com/ask-lang/ask-template.git
cd ask-template

Project Structure

ask-template/
├── asconfig.json        # AssemblyScript config
├── askconfig.json       # ask-lang config
├── build/              
│   └── metadata.json    # Contract metadata
├── flipper.ts          # Contract code
├── index.d.ts          # TypeScript definitions
├── package.json        # Dependencies
└── tsconfig.json       # TypeScript config

Contract Development

Basic Contract Structure

// Event Definition
@event({ id: 1 })
export class FlipEvent {
    flag: bool;
    constructor(flag: bool) {
        this.flag = flag;
    }
}

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

// Contract Logic
@contract
export class Contract {
    // Contract implementation
}

Key Components

1. Storage

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

2. Contract Methods

@contract
export class Contract {
    // Constructor
    @constructor()
    default(flag: bool): void {
        this.data.flag = flag;
    }

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

    // Read-only Method
    @message()
    get(): bool {
        return this.data.flag;
    }
}

3. Events

@event({ id: 1 })
export class FlipEvent {
    flag: bool;
    constructor(flag: bool) {
        this.flag = flag;
    }
}

// Emitting events
env().emitEvent(new FlipEvent(true));

Building Your Contract

# Install dependencies and build
yarn && yarn build flipper.ts

This generates:

  • flipper.optimized.wasm: Compiled WebAssembly code

  • metadata.json: Contract metadata

  • flipper.wat: WebAssembly text format (human-readable)

Deployment Process

  1. Select your target network

  2. Upload contract files:

    • metadata.json for ABI

    • flipper.optimized.wasm for contract code

  3. Follow the deployment wizard

  4. Confirm deployment success

Additional Resources

Documentation

Support

Need help? Join our Discord Community

Development Tips

  • Use TypeScript-aware IDEs for better development experience

  • Keep track of event IDs to avoid conflicts

  • Test thoroughly before deployment

  • Monitor gas usage and optimization

Last updated