> For the complete documentation index, see [llms.txt](https://docs.uomi.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.uomi.ai/build/wasm-smart-contracts/basic-ink-contract.md).

# Basic ink! Contract

### Project Structure

Each ink! contract requires its own crate with two essential files:

* `Cargo.toml`: Project configuration and dependencies
* `lib.rs`: Contract implementation

> 💡 **Tip**\
> You can use Swanky Suite to quickly bootstrap a new project. Check out the Swanky CLI guide for details.

### Contract Configuration

#### Cargo.toml Setup

Your `Cargo.toml` should include the following sections:

```toml
[package]
name = "my_contract"
version = "0.1.0"
authors = ["Your Name <name@email.com>"]
edition = "2021"

[dependencies]
ink = { version = "4.3", default-features = false}
ink_metadata = { version = "4.3", features = ["derive"], optional = true }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2.5", default-features = false, features = ["derive"], optional = true }

[dev-dependencies]
ink_e2e = { version = "4.3" }

[lib]
path = "lib.rs"

[features]
default = ["std"]
std = [
    "ink/std",
    "scale/std",
    "scale-info/std"
]
ink-as-dependency = []
e2e-tests = []
```

### Contract Implementation

#### Minimum Requirements

Every ink! contract must include:

> ⚠️ **Required Elements**
>
> 1. `no_std` attribute for non-standard library compilation
> 2. Contract module marked with `#[ink::contract]`
> 3. Storage struct with `#[ink(storage)]`
> 4. At least one constructor with `#[ink(constructor)]`
> 5. At least one message with `#[ink(message)]`

#### Basic Contract Template

```rust
#![cfg_attr(not(feature = "std"), no_std)]

#[ink::contract]
mod my_contract {
    /// Contract storage
    #[ink(storage)]
    pub struct MyContract {}

    impl MyContract {
        /// Contract constructor
        #[ink(constructor)]
        pub fn new() -> Self {
            Self {}
        }

        /// Contract message
        #[ink(message)]
        pub fn do_something(&self) {
            ()
        }
    }
}
```

### Example Contracts

#### Flipper Contract

The [flipper contract](https://github.com/paritytech/ink-examples/blob/main/flipper/lib.rs) is the simplest example provided by the ink! team, perfect for understanding basic contract structure.

### Best Practices

1. **Project Organization**
   * Keep one contract per crate
   * Use meaningful names for contract modules
   * Organize tests in a separate module
2. **Code Structure**
   * Group related functionality together
   * Document your code with comments
   * Follow Rust naming conventions
3. **Testing**
   * Include unit tests
   * Add integration tests where needed
   * Use ink!'s testing utilities


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.uomi.ai/build/wasm-smart-contracts/basic-ink-contract.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
