# rootchain-macros
[](https://crates.io/crates/rootchain-macros)
[](../../LICENSE)
> **Procedural macros for the RootChain smart contract framework.**
This crate provides the `#[rootchain_contract]` derive macro, which eliminates the boilerplate required to write smart contracts targeting the RootChain WASM virtual machine.
---
## What's Inside
| `#[rootchain_contract]` | Generates the WASM entry point, ABI dispatch table, and input/output glue code for a smart contract struct |
---
## Installation
This crate is typically used via `rootchain-std`, which re-exports it. You rarely need to add it directly.
```toml
# Use via rootchain-std (recommended):
[dependencies]
rootchain-std = { version = "1.0.2", default-features = false }
# Or use directly:
[dependencies]
rootchain-macros = "1.0.2"
```
---
## Usage
The `#[rootchain_contract]` macro is applied to an `impl` block and generates a WASM-compatible dispatch function. Your contract methods become callable ABI endpoints.
```rust
use rootchain_std::prelude::*;
pub struct MyToken;
#[rootchain_contract]
impl MyToken {
// Method 0: Initialize the contract
pub fn init(&mut self, _input: &[u8]) {
// Set initial state
}
// Method 1: A callable contract method
pub fn transfer(&mut self, input: &[u8]) {
// Deserialize input, apply state changes
}
}
```
### How It Works
The macro generates:
1. A `#[no_mangle] pub extern "C" fn apply(method_id: u32)` entry point.
2. A dispatch table that routes `method_id` to the correct method on your struct.
3. Automatic reading of WASM host input and writing of output.
---
## License
MIT — See [LICENSE](../../LICENSE) for details.