# Modules

There are two types of smart contracts in **dfinance**: module and script.

Difference between them that module is published into blockchain storage and is stored under the publisher account, while script is simply a transaction-as-script and can only operate with existing modules.

The Move Book also has a section about [modules](https://move-book.com/syntax-basics/module.html) in Move language.

## Write a module

Let's see an example of a small module that will just add two numbers (a and b):

```rust
module Math {
    public fun add(a: u64, b: u64): u64 {
        a + b
    }
}
```

Let's compile this module using **dncli**. Compiler requires sender's address as it's included into bytecode. This address will then be verified on module publish.

```
dncli q vm compile <path-to-mvir> <address> --to-file <output file>
```

Replace variables in this pattern with your own and you will get a compiled module in the specified output file. When it's done, you can publish your module:

```
dncli tx vm publish <output file> --from <account>
```

Check your transaction by querying its id, which was returned in the output.

```
dncli q tx <id>
```

If you see a **contract\_status** event, with status **keep** inside, everything published fine!

When it's done your module is be published under your address, and you and other users can access it in their modules or scripts:

```rust
use {{address}}::Math;
```

Just replace `{{address}}` with yours and you can use this module.


---

# 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.dfinance.co/move_vm/modules.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.
