Gotchas
The short list. Each item links to the page that explains it.
Numbers and arguments
Section titled “Numbers and arguments”u64,i64andVec<u8>travel as decimal strings and base64url, in arguments, results, record fields, errors and events. A client sends{"size": "7"}, not{"size": 7}.- The same types nested in another type (
Vec<u64>,Option<Vec<i64>>) do not compile: wrap them in aRecordor send strings (SDK macros). - A
u64inside your own plain serde struct reaches JSON as a number, which JavaScript may round. Use aRecord, whose derive converts it; on a#[derive(AbiType)]type, give the field its D20 helper or mark it#[abi(plain)]so the ABI says it is a number (unmarked, it does not compile; SDK macros). - Arguments are camelCase (
room_id→roomId), and unknown keys are refused (BadArgs).
- Renaming a state field or changing its type orphans its data: an upgrade keeps the state and has no migration step (Upgrades & state).
- A record must not also derive
Serialize/Deserialize:#[derive(Record)]writes them. - Uniqueness belongs in the key or a
unique(..)constraint, not in a check before an insert. - Prefer
env::unique_id()to aCounterfor ids. - A table’s size is
len(), one read;iter().count()reads every record. A table stored by an older SDK counts its records onlen()until its next insert or removal, and a release built with such an SDK does not keep the length: never go back to one (The length). - Multi-row reads are pages of at most 1,000: a view that answers a client
returns one page and its
next. Inside a run,iter()walks every page through one cursor (Iterating). - A run makes at most 10,000 writes. Use
extendon a vector, map or set, not apushorinsertper value: it writes the length once, so it costs half the writes (Costs and limits). Vector::insertandremoverewrite every later element; useswap_removewhen order does not matter, and aSetrather thanVector::containsto test membership.
Access
Section titled “Access”- A method with no attribute admits any signed-in account the node lets reach
the app; org membership is the app’s to check with
guards(Access control). - Take the caller from
env::caller()or a guard, never from an argument. #[app::error]and#[app::event]must be in the#[app::logic]module, or the ABI lists none of them. Every field needs a name:Invalid(String)does not compile,Invalid { reason: String }does.- Every app is in an organization (one its creator is in, or one made with it), and a cross-app call reaches only apps in the same organization.
- A call that fails writes nothing and emits nothing; a panic is a trap, not an app error (Error handling).
env::xcallonly queues a message: it is delivered after the entry commits, and only if the run succeeds (Cross-app calls).- Only views may search; a call that searches traps (Search).
env::fetch, actions and cross-app calls answer an error on the host target; test them withTestApp(Testing).- A read-only team member reaches an app’s views only: a call to any other
method is refused with
403before it runs. files::openworks only inside an#[app::compute]run; a call or view gets a file’s size and hash fromBlobRef::info(Files and blobs).
Build and ship
Section titled “Build and ship”- An SDK 0.12 app (a WASM core module,
wasm32-unknown-unknown) is refused at upload and install (400 UNSUPPORTED_BUNDLE); one left over from before answers410 UNSUPPORTED_ENGINE. Rebuild oncalimero-sdkforwasm32-wasip2withmeroctl app build. - Sign every release of a package with the same key: another key is another package, not an upgrade (Packaging & signing).
- Bump
#[app::state(version = N)]with every state change;meroctl app sign --previous(andmeroctl app pack --previous) refuses a removed or retyped state field without it.