Skip to main content
Withdraw collateral from your app in two steps: get an admin signature from the Rain API, then sign and submit on-device. The SDK runs the entire on-chain portion for you: it builds the EIP-712 message, encodes the calldata, signs through the resolved wallet, and submits the transaction. The SDK’s built-in Rain API client can fetch the signature itself, so the whole flow can run in-app. Alternatively, your backend fetches the signature and forwards it to the app. For background on how collateral contracts work, see Withdraw Collateral and Managing Collateral.

Withdrawal flow overview

The full round trip looks like this:
📱Mobile App
🌧️Rain API
⚙️RainClient
⛓️Blockchain
1App → Rain APIGet withdrawal signature
2Rain API → AppAdmin signature, salt, expiresAt
3App → RainClientwithdrawCollateral(…)
4RainClient → ChainCheck admin authorization, sign & submit
5Chain → AppTransaction hash
The steps above, in text:
Getting the admin signature requires Rain API credentials. Use the built-in Rain API client with a runtime-delivered, scoped key, or keep the call server-side with your primary Api-Key and forward the result. Never ship your primary Api-Key in a mobile app.
1

Get the contract and admin signature

With the built-in Rain API client configured, fetch the user’s collateral contract and the admin signature directly in the app:
If Rain hasn’t produced the signature yet, the SDK throws RAIN_303 carrying the reported status and an optional retryAfter hint: retry after that interval.Alternatively, fetch the signature from your backend with the server-side SDK and pass the salt / signature / expiresAt values into the app; the on-chain step is identical:
TypeScript
2

Withdraw

Pass the admin signature to withdrawCollateral. The SDK builds the transaction, signs it through the resolved wallet (the provider must support typed-data signing), submits it, and returns the transaction hash.
Platform differences:On Android, addresses are checksummed and validated up front: malformed input throws RAIN_102.
Before signing, the SDK checks on-chain that the resolved wallet is one of the collateral’s admin signers. A wallet that is definitively not authorized throws RAIN_407 (naming the wallet and proxy) before any signing round-trip, instead of an opaque on-chain InvalidSignature() revert. If the check cannot run (RPC failure), the withdrawal proceeds.

Estimate the withdrawal fee

Estimate the network fee before submitting.
Fee estimation builds the full transaction, including an EIP-712 signTypedData call through the provider. That means estimate-then-withdraw signs twice, and estimation can surface a signing prompt (for example biometrics on Turnkey). The collateral-admin check also runs during estimation, so RAIN_407 is possible here too. iOS returns Decimal; Android returns Double.

Manual building (bring your own submission)

To build the withdrawal calldata yourself and submit with your own wallet, use the wallet-agnostic builders: they never resolve a provider (though Android’s build() still requires at least one registered).

Error handling

Withdrawal methods can throw: See the full Error Reference for handling patterns.

What’s next

Withdraw Collateral (Guide)

Contract architecture and server-side withdrawal examples.

Authentication

Configure the built-in Rain API client and session tokens.

Error Reference

Handle SDK errors with standardized error codes.