Expand description
Module for Miden SDK macros
§How to use WIT generation.
An account component is written in three parts:
- A
#[component_storage]struct declaring the component’s#[storage(...)]fields. - A
#[component]traitdeclaring the component’s API. The trait name yields the WIT interface name and its methods yield the exported functions. - A
#[component]impl Trait for Storageblock providing the behavior.
Add #[export_type] on every type that is used in an exported method signature.
Example:
ⓘ
#[export_type]
pub struct StructA {
pub foo: Word,
pub asset: Asset,
}
#[export_type]
pub struct StructB {
pub bar: Felt,
pub baz: Felt,
}
#[component_storage]
struct MyAccountStorage;
#[component]
trait MyAccount {
fn foo(&self, a: StructA) -> StructB;
}
#[component]
impl MyAccount for MyAccountStorage {
fn foo(&self, a: StructA) -> StructB {
...
}
}Custom #[export_type] types referenced in component method signatures must be nameable from
the crate root (declared at, or use-imported into, the crate root).
§Escape hatch (disable WIT generation)
in a small fraction of the cases where the WIT generation is not possible (think a type defined only in an external WIT file) or not desirable the WIT generation can be disabled:
To disable WIT interface generation:
- Don’t use the
#[component]trait/impl macros; keep#[component_storage]on the storage struct;
To use manually crafted WIT interface:
- Put the WIT file in the
witfolder; - call
miden::generate!();andbindings::export!(MyAccountStorage); - implement
impl Guest for MyAccountStorage;
Macros§
- generate
- Generate bindings for an input WIT document.
Attribute Macros§
- account
- Generates typed active and foreign account bindings for account dependencies on an empty wrapper struct.
- auth_
script - Marks a component method as the authentication procedure entrypoint (
#[auth_script]). - component
- Defines an account component’s API and generates the WIT interface.
- component_
storage - Wires storage metadata for an account component’s storage struct.
- export_
type - Generates an equvalent type in the WIT interface. Required for every type mentioned in the public methods of an account component.
- note
- Marks a type/impl as a note script definition.
- note_
script - Marks a method as the note script entrypoint (
#[note_script]). - tx_
script - Marks the function as a transaction script