> For the complete documentation index, see [llms.txt](https://quantumwing.gitbook.io/quantumwing/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://quantumwing.gitbook.io/quantumwing/smart-contract-library/overview.md).

# Overview

Reference contracts shipped in contracts/

QuantumWing ships eleven reference contracts under [`contracts/`](https://github.com/quantumwing/protocol/tree/master/contracts). Each contract is a `no_std` Rust crate that compiles to WASM and runs on the QWVM.

The contracts double as:

* **Reference implementations** for token / DEX / governance / oracle developers
* **Foundation primitives** that downstream contracts can build on (a stablecoin needs an oracle; a DEX needs a token; a DAO needs a governance vote)
* **Audit surface** for the external security audit (Tier A-5 in [Pre-Launch Status](/quantumwing/roadmap/pre-launch-status.md))

## Token standards

| Page                                                     | Folder                   | Size   | Purpose                             |
| -------------------------------------------------------- | ------------------------ | ------ | ----------------------------------- |
| [QRC-20](/quantumwing/smart-contract-library/qrc20.md)   | `contracts/qrc20-rust/`  | 6.4 KB | Fungible tokens (ERC-20-equivalent) |
| [QRC-721](/quantumwing/smart-contract-library/qrc721.md) | `contracts/qrc721-rust/` | 8 KB   | NFTs (ERC-721-equivalent)           |
| [WQGEN](/quantumwing/smart-contract-library/wqgen.md)    | `contracts/wqgen-rust/`  | 9 KB   | Wrapped native QWING                |

## Account abstraction

| Page                                                       | Folder                                                                          | Size     | Purpose                                        |
| ---------------------------------------------------------- | ------------------------------------------------------------------------------- | -------- | ---------------------------------------------- |
| [ERC-4337](/quantumwing/smart-contract-library/erc4337.md) | `contracts/aa-entrypoint-rust/` (10 KB) + `contracts/aa-account-rust/` (5.1 KB) | combined | Singleton EntryPoint + reference smart account |

## DeFi primitives

The DeFi-flavored contracts (oracle, DEX, stablecoin, governance) live under [DeFi Primitives](/quantumwing/defi-primitives/overview.md). They share the same Rust/WASM ABI conventions — see below.

## Wallet contracts

| Page                                                             | Folder                   | Size    | Purpose                       |
| ---------------------------------------------------------------- | ------------------------ | ------- | ----------------------------- |
| [QWSafe Multi-sig](/quantumwing/wallets-and-clients/multisig.md) | `contracts/qwsafe-rust/` | 15.5 KB | M-of-N owner threshold wallet |

## Common ABI conventions

All reference contracts share these conventions:

* Exported functions are `extern "C" fn name() -> u32` returning a status code.
* Arguments are written by the host into a fixed-size `ARG_BUFFER` static (256 bytes by default). The contract exports `get_arg_buffer_ptr()` so the host can locate it.
* Return values are written into a fixed-size `RET_BUFFER` static and the host reads them back via `get_ret_buffer_ptr()` + `get_ret_len()`.
* Storage keys are ASCII strings of the form `prefix:field` or `prefix:{address}` (32 hex chars). 32 bytes is the maximum key length; longer keys are hashed into a 32-byte slot.
* Storage values are raw bytes (not RLP, not JSON) — encoding is the contract's responsibility.
* Events are EVM-shaped: `topics[0] = keccak256("EventName(arg0,arg1,...)")`, `topics[1..]` are 32-byte indexed parameters, `data` is ABI-encoded non-indexed parameters.

## Build all contracts

```bash
cd contracts
for d in */; do
  cd "$d"
  if [ -f "Cargo.toml" ]; then
    cargo build --release --target wasm32-unknown-unknown
  fi
  cd ..
done
```

Output WASM at:

```
contracts/<name>-rust/target/wasm32-unknown-unknown/release/<name>.wasm
```

## Status codes

```
0   OK
1   NotInitialized
2   AlreadyInitialized
3   Unauthorized
4   InvalidArgument
5   InsufficientBalance
6   InsufficientAllowance
7   StorageMissing
8   ReentrancyDetected
9   ArithmeticOverflow
10  ZeroAddress
11+ contract-specific
```

## Related

* [QWVM Overview](/quantumwing/smart-contracts/qwvm.md) — host functions and execution model
* [WASM Gas Metering](/quantumwing/smart-contracts/wasm-gas-metering.md) — gas costs at the bytecode level


---

# 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 following URL with the `ask` and `goal` query parameters:

```
GET https://quantumwing.gitbook.io/quantumwing/smart-contract-library/overview.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `build a script that syncs our docs to a CMS` lets GitBook tailor the answer to that use case.

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.
