Skip to main content

Deposit with Referral

A UserMetadata account stores the referrer information. The referrer must be included when the account is created. After it is set, the referrer cannot be changed.
1

Import Dependencies

Import the required packages for Solana RPC communication, Kamino SDK operations, and Kit transaction building.
2

Setup Market and Check Existing Referrer

Load the keypair, initialize the market, and check whether a referrer is already associated with the account.
Check if a referrer is already associated with the account and set the referrer address.
Once a UserMetadata account has a referrer, it cannot be changed. If a referrer is already set, any new referrer value is ignored, and the original referrer continues to receive commission from the user’s borrowing activity.
3

Build Deposit Instructions with Referrer

Generate deposit instructions that include the referrer information.
The referrer earns commission from the user’s future borrowing activity. This creates a permanent, non-revocable link between the user and the referrer.
4

Send Initial Transaction

Fetch the latest blockhash and build the transaction message.
Sign and send the transaction.
5

Handle Retry Logic

Detect and handle setup-related errors that may occur.
When setup instructions are included, the first transaction may fail with error 0x17a3. The retry logic handles this by waiting for blockchain state to settle, reloading the market, and rebuilding instructions.
Wait for blockchain state to settle and reload the market.
Rebuild the deposit instructions with the reloaded market state.
Fetch a fresh blockhash and build the retry transaction.
Sign and send the retry transaction.
The deposit with referral is complete. The referrer is now permanently linked to the account and will earn commission from the user’s future borrowing activity.