For the complete documentation index, see llms.txt. This page is also available as Markdown.

Instant Withdrawal Script

An instant withdrawal lets you withdraw funds without waiting the normal 12-hour cooldown. You select a fee option matching how fast you want it processed, and withdraw through a bridge. This guide shows how to do it without a frontend.

Instant withdrawals work in two steps:

  1. On-chain: you transfer your allocated balance to a bridge.

  2. Off-chain: you select a fee option, and the backend schedules the withdrawal for execution.

Before you start

You'll need:

  • Python 3.8 or newer

  • A wallet private key (for signing and paying gas)

  • An RPC URL for the chain you're withdrawing from

  • The Python script from the reference repo

Setup

Create and activate a virtual environment, then install dependencies:

python -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Configure .env

The script reads its configuration from a .env file. Use the private key for the wallet you want to withdraw from, and an RPC provider:

Withdrawing 1 USDC means passing 1000000, since USDC on Base has 6 decimals.

Running the script

From the project root:

Once started, the script walks through all the steps automatically.

What the script does, step by step

The flow below maps directly to the Python code.

1. Sign in with your wallet (SIWE)

The script proves wallet ownership with Sign-In With Ethereum and gets an access token, so it can talk to the Instant Withdrawal backend.

This token is required for all Instant Withdrawal API calls.

2. Lock fee options for your withdrawal amount

The script asks the backend for the fee options for a specific amount. This temporarily locks the options so rates can't change.

3. Deallocate funds from trading (on-chain)

If your funds are currently allocated to trading, free them first. The script fetches a Muon uPNL signature, formats it for the contract, and sends the transaction.

This must complete on-chain before continuing.

4. Transfer funds to the withdrawal bridge (on-chain)

Once funds are free, they're transferred into the Instant Withdrawal bridge.

After confirmation, the script extracts a transactionId from the emitted event. This ID is required for the next step.

5. Fetch pending fee policies

With the bridge transfer on-chain, the script fetches the valid fee options tied to that transfer.

6. Select a fee policy and schedule the withdrawal

The script picks the fastest option and submits it.

Once done, the withdrawal is scheduled and executes automatically.

Reference implementation

This repository has a Python script showing the full Instant Withdrawal flow.

Last updated