# 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](https://github.com/ask-lang/ask/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

```bash
npm install --global yarn
```

#### 2. Clone Template Repository

```bash
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

```typescript
// 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**

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

**2. Contract Methods**

```typescript
@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**

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

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

### Building Your Contract

```bash
# 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. Access [polkadot.js](https://polkadot.js.org/apps/)
2. Select your target network
3. Upload contract files:
   * `metadata.json` for ABI
   * `flipper.optimized.wasm` for contract code
4. Follow the deployment wizard
5. Confirm deployment success

### Additional Resources

#### Documentation

* [Official ask! Documentation](https://github.com/ask-lang/ask)
* [Polkadot Treasury Proposal](https://polkadot.polkassembly.io/post/949)

#### Support

Need help? Join our [Discord Community](https://discord.com/invite/KXh72E2gPe)

#### 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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.uomi.ai/build/wasm-smart-contracts/ask-development.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
