diff --git a/packages/controller/src/utils/solana/index.ts b/packages/controller/src/utils/solana/index.ts index 70d5efe9a2..bb3b4f8edb 100644 --- a/packages/controller/src/utils/solana/index.ts +++ b/packages/controller/src/utils/solana/index.ts @@ -90,6 +90,7 @@ export class Transaction { // Build transaction using micro-sol-signer if (this._transaction) { // If we have a decoded transaction, re-serialize it + console.log("[Transaction.serialize] Re-encoding existing transaction"); return Buffer.from(sol.Transaction.encode(this._transaction)); } @@ -98,13 +99,38 @@ export class Transaction { throw new Error("Transaction requires feePayer and recentBlockhash"); } - const txHex = sol.createTxComplex( + console.log( + "[Transaction.serialize] Building new transaction with", + this._instructions.length, + "instructions", + ); + console.log("[Transaction.serialize] feePayer:", this.feePayer.toString()); + console.log( + "[Transaction.serialize] recentBlockhash:", + this.recentBlockhash, + ); + + // Use createTxComplex which returns a base64-encoded transaction with empty signatures + const txBase64 = sol.createTxComplex( this.feePayer.toString(), this._instructions, this.recentBlockhash, ); - return Buffer.from(txHex, "hex"); + console.log( + "[Transaction.serialize] createTxComplex returned base64 length:", + txBase64.length, + ); + + // Decode the base64 string to get the transaction bytes + const buffer = Buffer.from(txBase64, "base64"); + console.log("[Transaction.serialize] Final buffer length:", buffer.length); + console.log( + "[Transaction.serialize] First 32 bytes:", + Array.from(buffer.slice(0, 32)), + ); + + return buffer; } serializeMessage(): Buffer { diff --git a/packages/controller/src/wallets/phantom/index.ts b/packages/controller/src/wallets/phantom/index.ts index ef9d3833c1..e4177cdffa 100644 --- a/packages/controller/src/wallets/phantom/index.ts +++ b/packages/controller/src/wallets/phantom/index.ts @@ -135,7 +135,25 @@ export class PhantomWallet implements WalletAdapter { } try { + console.log( + "[PhantomWallet.sendTransaction] Received serialized_txn length:", + serailized_txn.length, + ); + console.log( + "[PhantomWallet.sendTransaction] First 32 bytes:", + Array.from(serailized_txn.slice(0, 32)), + ); + console.log( + "[PhantomWallet.sendTransaction] Deserializing with Transaction.from...", + ); + const txn = Transaction.from(serailized_txn); + + console.log("[PhantomWallet.sendTransaction] Successfully deserialized"); + console.log( + "[PhantomWallet.sendTransaction] Sending to Phantom provider...", + ); + const provider = this.getProvider(); const result = await provider.signAndSendTransaction(txn); return { diff --git a/packages/keychain/src/utils/solana/index.ts b/packages/keychain/src/utils/solana/index.ts index a77ee5fa5a..b1ebd87463 100644 --- a/packages/keychain/src/utils/solana/index.ts +++ b/packages/keychain/src/utils/solana/index.ts @@ -149,15 +149,42 @@ export class Transaction { throw new Error("Transaction requires feePayer and recentBlockhash"); } - // Create the transaction with micro-sol-signer - const txHex = sol.createTxComplex( + console.log( + "[keychain/Transaction.serialize] Building transaction with", + this.instructions.length, + "instructions", + ); + console.log( + "[keychain/Transaction.serialize] feePayer:", + this.feePayer.toString(), + ); + console.log( + "[keychain/Transaction.serialize] recentBlockhash:", + this.recentBlockhash, + ); + + // createTxComplex returns a base64-encoded string, not hex! + const txBase64 = sol.createTxComplex( this.feePayer.toString(), this.instructions, this.recentBlockhash, ); - // Convert hex string to Uint8Array - return new Uint8Array(Buffer.from(txHex, "hex")); + console.log( + "[keychain/Transaction.serialize] createTxComplex returned base64 length:", + txBase64.length, + ); + + // Decode the base64 string to get the transaction bytes + const buffer = new Uint8Array(Buffer.from(txBase64, "base64")); + + console.log("[keychain/Transaction.serialize] Final buffer length:", buffer.length); + console.log( + "[keychain/Transaction.serialize] First 32 bytes:", + Array.from(buffer.slice(0, 32)), + ); + + return buffer; } }