# Codegen attributes

## #\[cmd]

When `move-to-ts` is invoked with the `-c` (`--gen-cli`) flag, it will output a `cli.ts` (invoked with `yarn cli`) that contains one command for every `entry` function that's decorated with the `#[cmd]` attribute.

Example in Move:

```
#[cmd(desc=b"Add new token into registry")]
public entry fun add_token_script<TokenType>(
    admin: &signer,
    name: vector<u8>,
    symbol: vector<u8>,
    description: vector<u8>,
    decimals: u8,
    logo_url: vector<u8>,
    project_url: vector<u8>,
) acquires TokenRegistry {
    ...
}
```

Generated CLI:

```
$ yarn cli
Usage: move-ts-cli [options] [command]

Options:
  -c, --config <path>                  path to your aptos config.yml (generated with "aptos init")
  -p, --profile <PROFILE>              aptos config profile to use (default: "default")
  -h, --help                           display help for command

Commands:
  coin_registry:add-token-script <TYPE_TokenType> <name> <symbol> <description> <decimals> <logo_url> <project_url>  
                                       Add new token into registry
```

## #\[method]

The `#[method]` attribute allows you to attach specific Move functions to specified Move resource types, and use them from TypeScript as ordinary class methods.

Example in Move (taken from [Econia](https://github.com/econia-labs/econia/blob/ff71a83fa0462315f8c825851c05a4a3f4dbfb4f/src/move/econia/sources/market.move#L48))

```
    #[method(
        book_orders_sdk,
        book_price_levels_sdk,
        get_orders_sdk,
        simulate_swap_sdk
    )]
    /// An order book for the given market
    struct OrderBook<phantom B, phantom Q, phantom E> has key {
        ...
    }

    
    /// Calculate expected result of swap against an `OrderBook`.
    fun simulate_swap_sdk<B, Q, E>(
        order_book_ref_mut: &mut OrderBook<B, Q, E>,
        style: bool,
        coins_in: u64
    ): (
        u64,
        u64
    ) {
        ...
    }
```

Usage in TypeScript:

```typescript
// first fetch OrderBook resource from chain
const orderBook = await app.loadOrderBook(...);
// performs computation using fetched state
const [quoteReceived, basePaid] = orderBook.simulate_swap_sdk(true, u64(100000));
```

## #\[app]

The `#[app]` attribute, used on functions, tells `move-to-ts` to include a particular function in the App interface generated. It allows you to call arbitrary move functions from TypeScript.

Example (taken from [lending tutorial](https://github.com/hippospace/tutorial-lending/blob/45ac96e003c0fbcd9b52da936022ac562de9550d/sources/lending.move#L331)):

```
#[app]
public fun global_get_user_limits(user: address): (bool, u64, u64) acquires User, LendingProtocol {
    let user = borrow_global<User>(user);
    let protocol = borrow_global<LendingProtocol>(@hippo_tutorial);
    user_get_limits(user, protocol)
}
```

When the `#[app]` attribute is applied on `global_get_user_limits`, the following interface is exposed from the App interface:

```typescript
app_global_get_user_limits(
  user: HexString,
) {
  return global_get_user_limits_(user, this.cache);
}
```

## #\[query]

The `#[query]` attribute allows you to:

1. Execute arbitrary computation in Move under simulation mode using realtime onchain data
2. Obtain a specified output from fullnode as serialized return value

The targetted use case is to allow frontends/arb bots to obtain realtime quotes from fullnodes directly. We are reworking the interface of this query feature to make it simpler and more general (hint: we'll use `script` transactions!). For a contrived example of the existing, and somewhat inconvenient, interface, please refer to [this](https://github.com/hippospace/move-to-ts#query).

```
```


---

# 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://hippo-labs.gitbook.io/dev/move-to-ts/codegen-attributes.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.
