Best Practices
Recommended patterns for cilantro-sdk and cilantro-react
Best Practices
-
Configure once at startup; use setAuth when the user logs in or the token changes. See Configuration.
-
React apps — Use CilantroProvider and useAuth / useWallet; the provider sets the JWT when the user logs in. See React Setup.
-
Polyfills — Import
cilantro-sdk/polyfillsat the very top of your browser entry file. -
Non-custodial in browser — Use a storage adapter (e.g. IndexedDB) and pass deviceKeyManager wherever helpers need it; never skip it for email/phone signers. See Helpers.
-
Prefer helpers for email/phone/passkey: createEmailSignerHelper, getEmailSignerKeypair, sendSOLWithSigner, etc., instead of raw wallet API + manual key handling.
-
Errors — Use extractErrorMessage (and extractResponseData if you prefer unwrapping); handle DeviceKeyNotFoundError and DeviceKeyMismatchError with a clear message (e.g. "Re-create the signer on this device"). See Response and errors and Error handling.
-
Secrets — Never hardcode API keys; use environment variables.