> ## Documentation Index
> Fetch the complete documentation index at: https://rain-sandbox-trial.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Funding & Transfers

> Deposit collateral, process withdrawals, and check balances using the Rain SDK, for both Rain-managed and Partner-managed programs.

Before a cardholder can spend, you need to add collateral to their account. How you do this depends on your [management model](/docs/first-steps).

<Info>
  **Rain-managed** programs use per-user smart contracts. You deposit tokens on-chain and the credit limit updates automatically. **Partner-managed** programs use a single collateral account funded through the Dashboard.
</Info>

## Fund a user's account (Rain-managed)

<Steps>
  <Step title="Get the user's contract">
    Retrieve the smart contract address where you'll deposit tokens:

    <CodeGroup>
      ```ts TypeScript theme={null}
      const contracts = await client.users.retrieveContracts(userId);
      const contract = contracts[0];

      console.log(`Deposit to: ${contract.depositAddress}`);
      console.log(`Chain ID: ${contract.chainId}`);
      console.log(`Accepted tokens:`, contract.tokens);
      ```

      ```python Python theme={null}
      contracts = client.users.retrieve_contracts(user_id)
      contract = contracts[0]

      print(f"Deposit to: {contract.deposit_address}")
      print(f"Chain ID: {contract.chain_id}")
      print(f"Accepted tokens: {contract.tokens}")
      ```
    </CodeGroup>

    Each contract includes a `depositAddress`, `chainId`, and a list of accepted `tokens` with their on-chain addresses. See [Supported Chains & Tokens](/docs/supported-chains-and-tokens) for the full list of networks.
  </Step>

  <Step title="Deposit tokens on-chain">
    Send supported tokens (e.g., USDC) to the `depositAddress` on the specified chain. This is a standard on-chain transfer. Use your preferred web3 library (ethers.js, viem, web3.py, etc.).

    Once the deposit is confirmed on-chain, Rain automatically updates the user's credit limit.
  </Step>

  <Step title="Check the credit limit">
    Verify the balance updated after your deposit:

    <CodeGroup>
      ```ts TypeScript theme={null}
      const balances = await client.users.retrieveBalances(userId);

      console.log(`Credit limit: $${(balances.creditLimit / 100).toFixed(2)}`);
      console.log(`Spending power: $${(balances.spendingPower / 100).toFixed(2)}`);
      console.log(`Pending charges: $${(balances.pendingCharges / 100).toFixed(2)}`);
      console.log(`Balance due: $${(balances.balanceDue / 100).toFixed(2)}`);
      ```

      ```python Python theme={null}
      balances = client.users.retrieve_balances(user_id)

      print(f"Credit limit: ${balances.credit_limit / 100:.2f}")
      print(f"Spending power: ${balances.spending_power / 100:.2f}")
      print(f"Pending charges: ${balances.pending_charges / 100:.2f}")
      print(f"Balance due: ${balances.balance_due / 100:.2f}")
      ```
    </CodeGroup>

    | Field            | Description                                                     |
    | ---------------- | --------------------------------------------------------------- |
    | `creditLimit`    | Total credit available based on deposited collateral (in cents) |
    | `spendingPower`  | How much the user can still spend (in cents)                    |
    | `pendingCharges` | Authorized but not yet settled charges (in cents)               |
    | `postedCharges`  | Settled charges (in cents)                                      |
    | `balanceDue`     | Outstanding amount owed (in cents)                              |
  </Step>
</Steps>

## Process a withdrawal (Rain-managed)

To withdraw collateral, retrieve a withdrawal signature and submit it on-chain:

<CodeGroup>
  ```ts TypeScript theme={null}
  const signature = await client.users.signatures.retrieveWithdrawalSignature(
    userId,
    {
      token: '0xA0b8...eB48',     // token contract address
      adminAddress: '0x1234...5678', // your admin wallet
      amount: '1000000',            // amount in token decimals (e.g., 1 USDC = 1000000)
      recipientAddress: '0xabcd...ef01',
    },
  );

  // Use the signature with the Rain smart contract's withdraw function
  // See the full ethers.js example in Rain-Managed Programs
  ```

  ```python Python theme={null}
  signature = client.users.signatures.retrieve_withdrawal_signature(
      user_id,
      token="0xA0b8...eB48",
      admin_address="0x1234...5678",
      amount="1000000",
      recipient_address="0xabcd...ef01",
  )

  # Use the signature with the Rain smart contract's withdraw function
  ```
</CodeGroup>

See [Rain-Managed Programs](/docs/rain-managed-programs) for the full on-chain withdrawal flow with ethers.js.

## Check your balance (Partner-managed)

Partner-managed programs use a single collateral account. Fund it through the Dashboard, then check balances via the API:

<CodeGroup>
  ```ts TypeScript theme={null}
  const balances = await client.balances.retrieve();

  console.log(`Credit limit: $${(balances.creditLimit / 100).toFixed(2)}`);
  console.log(`Spending power: $${(balances.spendingPower / 100).toFixed(2)}`);
  ```

  ```python Python theme={null}
  balances = client.balances.retrieve()

  print(f"Credit limit: ${balances.credit_limit / 100:.2f}")
  print(f"Spending power: ${balances.spending_power / 100:.2f}")
  ```
</CodeGroup>

See [Partner-Managed Programs](/docs/partner-managed-programs) for details on adding collateral through the Dashboard.

## What's next

<Columns cols={3}>
  <Card title="Rain-Managed Programs" icon="link" href="/docs/rain-managed-programs">
    Full guide to on-chain collateral management.
  </Card>

  <Card title="Partner-Managed Programs" icon="building" href="/docs/partner-managed-programs">
    Dashboard-based funding and balance management.
  </Card>

  <Card title="Mobile Withdrawals" icon="mobile" href="/sdks/embedded-wallets-withdraw-collateral">
    Execute withdrawals from Android or iOS with the Client SDK.
  </Card>
</Columns>
