@@ -221,6 +221,10 @@ export class SolanaStreamClient extends BaseStreamClient {
221221 /**
222222 * Builds transaction instructions for creating a new stream/vesting contract without creating a transaction.
223223 * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
224+ *
225+ * For native SOL (isNative: true), SOL wrapping instructions are automatically included in the correct order
226+ * (before stream creation) to ensure the WSOL account exists when the stream creation instruction executes.
227+ *
224228 * @param {ICreateStreamData } data - Stream parameters including recipient, token, amount, schedule, and permissions
225229 * @param {Omit<ICreateStreamSolanaExt, "sender"> & { senderPublicKey: PublicKey } } extParams - Transaction configuration including sender public key, native token handling, and custom instructions
226230 * @returns Transaction instructions and metadata ID
@@ -250,6 +254,16 @@ export class SolanaStreamClient extends BaseStreamClient {
250254 tokenProgramId ? new PublicKey ( tokenProgramId ) : undefined ,
251255 ) ;
252256
257+ // CRITICAL: SOL wrapping must happen BEFORE stream creation instructions
258+ // This ensures the WSOL account exists and has sufficient balance when stream creation executes
259+ if ( isNative ) {
260+ const totalFee = await this . getTotalFee ( {
261+ address : partnerPublicKey . toString ( ) ,
262+ } ) ;
263+ const totalAmount = calculateTotalAmountToDeposit ( amount , totalFee ) ;
264+ ixs . push ( ...( await prepareWrappedAccount ( this . connection , tempSender . publicKey ! , totalAmount ) ) ) ;
265+ }
266+
253267 const {
254268 ixs : createIxs ,
255269 metadata,
@@ -261,14 +275,6 @@ export class SolanaStreamClient extends BaseStreamClient {
261275
262276 ixs . push ( ...createIxs ) ;
263277
264- if ( isNative ) {
265- const totalFee = await this . getTotalFee ( {
266- address : partnerPublicKey . toString ( ) ,
267- } ) ;
268- const totalAmount = calculateTotalAmountToDeposit ( amount , totalFee ) ;
269- ixs . push ( ...( await prepareWrappedAccount ( this . connection , tempSender . publicKey ! , totalAmount ) ) ) ;
270- }
271-
272278 await this . applyCustomAfterInstructions ( ixs , customInstructions , metadataPubKey ) ;
273279
274280 return {
@@ -281,6 +287,10 @@ export class SolanaStreamClient extends BaseStreamClient {
281287 /**
282288 * Builds a transaction for creating a new stream/vesting contract without signing or executing it.
283289 * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
290+ *
291+ * For native SOL (isNative: true), SOL wrapping instructions are automatically included in the correct order
292+ * (before stream creation) to ensure the WSOL account exists when the stream creation instruction executes.
293+ *
284294 * @param {ICreateStreamData } data - Stream parameters including recipient, token, amount, schedule, and permissions
285295 * @param {Omit<ICreateStreamSolanaExt, "sender"> & { senderPublicKey: PublicKey } } extParams - Transaction configuration including sender public key, native token handling, and custom instructions
286296 * @returns Transaction and metadata information
@@ -841,6 +851,25 @@ export class SolanaStreamClient extends BaseStreamClient {
841851 /**
842852 * Builds multiple transactions for creating stream/vesting contracts without signing or executing them.
843853 * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
854+ *
855+ * IMPORTANT: When using native SOL (isNative: true), you MUST execute the prepareTx FIRST and wait for confirmation
856+ * before executing the stream creation transactions. Otherwise, stream creation will fail with "InvalidAccountData".
857+ *
858+ * @example
859+ * ```typescript
860+ * const result = await streamClient.buildCreateMultipleTransactions(data, { isNative: true, senderPublicKey });
861+ *
862+ * // CRITICAL: Execute prepareTx first if it exists
863+ * if (result.prepareTx) {
864+ * await connection.sendAndConfirmTransaction(result.prepareTx, [signer]);
865+ * }
866+ *
867+ * // Only then execute stream creation transactions
868+ * for (const item of result.transactions) {
869+ * await connection.sendAndConfirmTransaction(item.tx, [signer]);
870+ * }
871+ * ```
872+ *
844873 * @param {ICreateMultipleStreamData } data - Stream base parameters and array of recipients with individual amounts and settings
845874 * @param {Omit<ICreateStreamSolanaExt, "sender"> & { senderPublicKey: PublicKey } } extParams - Transaction configuration including sender public key, native token handling, and custom instructions
846875 * @returns Multiple transaction information
0 commit comments