Expand description
Generate interfacing materials from a trait or impl that has
been annotated with the contract macro. This crate produces:
- Client-stub implementations for making contract calls
- Guest method stubs and external symbols for calling into the contract
- Test-registration code
Macros§
- export_
interface_ spec - Anchor a
#[contract]trait’s spec for inclusion. Spec shaking drops a trait’s (candidate) interface spec unless something anchors it — normally a#[contract] impl. Use this in an interface crate’s spec-carriermain.rsso building that crate on its own emits the interface’s full spec: - hash_
to_ array - Compute a
[u8; 32]at compile time: sha256 of the literal’s value (quotes stripped, escapes resolved). Accepts string and byte-string literals:hash_to_array!("foo")== sha256 of the 3 bytesfooand agrees withthruput_sdk::crypto::sha256(b"foo")at runtime and withsha256_static!/static_key!for the same string. - sha256_
array_ ident - Like
sha256_ident!(sha256 of the bare identifier’s text), but expands to a[u8; 32]array instead of aSHA256Hash. - sha256_
ident - Compute a
SHA256Hashat compile time: sha256 of the bare identifier’s text (no quotes —sha256_ident!(foo)hashes the 3 bytesfoo). - sha256_
static - Compute a
SHA256Hashat compile time: sha256 of the string literal’s value (quotes stripped, escapes resolved). - static_
key - Compute a
StorageKeyat compile time: sha256 of the string literal’s value (quotes stripped, escapes resolved).
Attribute Macros§
- contract
- Turn a trait, impl block, or free function into contract entrypoints, generating exports, a typed client, and spec registration.
- contract_
exception #[contract_exception]or#[contract_exception(version = "1.0.0", name = "...")]— full convenience macro: derives +#[repr(i32)]+impl Exn+impl ContractTypeName.- contract_
type - Make a struct or enum usable as a contract argument, return value, or
auth-token payload: derives XDR codecs, spec registration,
auth-handle walkers, and the
Mintablepreimage machinery. - exn
#[exn]or#[exn(version = "1.0.0")]— emitsimpl Exnwith a computed selector. Use this when you handle your own derives. For the full convenience macro, use#[contract_exception]instead.- storage
- Mark a struct as contract storage: generates
From<Keypath>so each field is bound to a storage slot derived from the struct’s keypath.
Derive Macros§
- Contract
Type Spec - Derive
ContractTypeSpec(plusContractTypeRefSpec, a linker anchor, and the raw typedef link-section fragment) for a struct or enum. - Deletable
- Event
- Derive event encoding, signature and spec metadata.
- Storage