Skip to main content

Withdrawal steps

Step 1: Request a withdrawal signature

Use the get user withdrawal signature endpoint.
  • Get the token info from the get issuing user contracts response.
  • If the response contains an error, carefully review the detailed error message provided to determine the cause before retrying the request.

Example errors and how to address them:

  • Token address not found:
    Double-check that the token address you provided matches the expected token for this contract and user.
  • Validation error – insufficient collateral:
    The requested withdrawal amount exceeds the available collateral balance in the contract. Adjust the amount to the maximum available balance and try again.

Step 2: Execute the withdrawal transaction

Use the signature to call withdrawAsset on the smart contract controller. You’ll need the following parameters:

Step 3: Execute with ethers.js

Code examples

V1 Contracts

This example uses the Issuing API and V1 contracts to request a signature and execute the transaction:

V2 Contracts - EVM

V2 contracts require an additional adminSignature and adminSalt, generated by the contract admin. For V2, Rain renamed the controllerAddress contract to coordinatorAddress which can be obtained from the get issuing user contracts response.

Generating Admin Signature (V2)

Use this helper to generate the required parameters for the withdrawal transaction:

V2.00 Contracts - Solana

For the imported main.json and main files, you may download them here.

V2.02 Contracts - Solana

MultiSig collateral contract

If your Solana contracts have been upgraded to v2.02, you will need to upgrade the withdrawal flow.
  1. Update the IDL files.
  2. Replace the line to get the withdrawSignature Account
  1. Replace the line to get the collateral account
  1. Update the withdraw instruction to specify the account that shall receive back the rent of the CollateralAdminSignatures:
Note: The account that receives the rent back in the withdraw must be the same account that paid for the rent when submitting the signature, other wise the withdraw transaction will revert.

Single Signer collateral contract

For Solana single-signer collateral accounts (where the owner is a traditional, self-custodied wallet), utilize the v2.02 withdrawal flow as described below. Ensure you provide the correct account structure required by the v2.02 program, including the owner’s signature (as the transaction signer) and the embedded coordinator signature. If you are new to the withdrawal process, you can refer to the examples repository for step-by-step guidance. If you’re already familiar with implementing multisig using a Solana program v2.01 or later, apply the changes highlighted in the above section to transition to single-signer v2.02 flows.
  1. Update the IDL files if it’s needed.
  2. Remove the lines to submit the collateral signature
  1. Replace the line to get the collateral account
  1. Replace the lines to create the withdraw collateral asset instruction
  1. Replace nonce property reference

Single Signer collateral contract with smart wallet or squad

If your Solana collateral is a single signer type with a smart wallet (e.g. Squad) as owner, you will need to adapt the v2.02 withdrawal flow to work with your smart wallet’s signing flow.
  1. Be sure to use the Squads multisig vault PDA as the owner of the single signer collateral account.
    • The vault PDA (not the multisig PDA itself) must be set as the owner in all owner references.
If you have questions about Squads multisig, refer to the example guidance.

V2 Contracts - Stellar

Stellar withdrawal requires coordinating with the Coordinator contract using signatures from the Rain API. The coordinatorAddress is automatically obtained from the controllerAddress field in the contracts API response.

Environment Setup

Create a .env.local file in your project root with the following variables:

Key Parameters

Workflow Overview

  1. Request Withdrawal Signature: Call the Rain API to get a signature for your withdrawal parameters
  2. Fetch Contract Data: Retrieve the user’s contracts to get the coordinatorAddress (from controllerAddress field)
  3. Build Transaction: Prepare a Soroban transaction with the withdrawal parameters and signatures
  4. Execute & Confirm: Send the transaction to Stellar and poll for confirmation
For the complete implementation, refer to the full example repository.