LogoLogo
WebsiteSubstrate Block ExplorerEVM Block ExplorerFaucet
  • Learn
    • Architecture
    • Staking
      • Proof of stake
    • Smart Contracts
    • Accounts
    • Infrastructure
      • Nodes
      • Agents
      • Models
      • IPFS
    • Security
      • OPOC
      • TSS
      • IPFS Integrity
      • Model Updates Integrity
    • Fees
    • Finney Testnet RPC Endpoints
  • Build
    • Address format
    • ink! Environment
    • Wasm Smart Contracts
      • Smart Contract Stack
      • Domain-Specific Languages (DSLs)
      • ink! Development
      • ask! Development
      • Basic ink! Contract
    • EVM Smart Contracts
      • Introduction to EVM Smart Contracts
      • HardHat
      • Your first EVM Smart Contract
      • Debug EVM Transactions
      • Precompiles
        • SR25519
        • Substrate ECDSA
        • XC20
    • Run a node
      • Run an archive node
        • Binary
      • Run a full node
      • Become a validator
        • Learn about Validators
        • Validator requirements
        • Spin up a validator
        • Set your identity
    • Build an Agent
      • Introduction
      • Development
      • Installing WASP
      • Agents API Reference
      • Available AI Models
Powered by GitBook
On this page
  • Introduction
  • Prerequisites
  • Environment Setup
  • Contract Development
  • Building Your Contract
  • Deployment Process
  • Additional Resources
Export as PDF
  1. Build
  2. Wasm Smart Contracts

ask! Development

Previousink! DevelopmentNextBasic ink! Contract

Last updated 5 months ago

⚠️ 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.

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

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

Access

Need help? Join our

View known issues
polkadot.js
Official ask! Documentation
Polkadot Treasury Proposal
Discord Community