Skip to main content

Withdraw Referrer Fees

1

Import Dependencies

2

Load Market and Initialize RPC

3

Check Accumulated Fees

Fees accrue per reserve, in that reserve’s token. Amounts are in lamports, so divide by the reserve’s mint factor.
4

Build Withdraw Instructions

Withdraw the unclaimed USDC fees to the wallet.
A wallet that has never earned fees in the reserve has no referrer token state for it, and the withdrawal fails with AccountOwnedByWrongProgram (3007).
5

Build the Transaction

6

Sign and Send

Fee withdrawal complete. The accumulated referral fees have been transferred to the referrer wallet.