66 */
77
88import { BuilderNamespace } from "./wasm/wasm_solana.js" ;
9+ import { Transaction } from "./transaction.js" ;
10+ import { VersionedTransaction } from "./versioned.js" ;
911
1012// =============================================================================
1113// Nonce Types
@@ -463,48 +465,58 @@ export interface TransactionIntent {
463465/**
464466 * Build a Solana transaction from a high-level intent.
465467 *
466- * This function takes a declarative TransactionIntent and produces serialized
467- * transaction bytes that can be signed and submitted to the network .
468+ * This function takes a declarative TransactionIntent and produces a Transaction
469+ * object that can be inspected, signed, and serialized .
468470 *
469- * The returned transaction is unsigned - signatures should be added before
470- * broadcasting.
471+ * The returned transaction is unsigned - signatures should be added via
472+ * `addSignature()` before serializing with `toBytes()` and broadcasting.
471473 *
472474 * @param intent - The transaction intent describing what to build
473- * @returns Serialized unsigned transaction bytes (Uint8Array)
475+ * @returns A Transaction object that can be inspected, signed, and serialized
474476 * @throws Error if the intent cannot be built (e.g., invalid addresses)
475477 *
476478 * @example
477479 * ```typescript
478480 * import { buildTransaction } from '@bitgo/wasm-solana';
479481 *
480482 * // Build a simple SOL transfer
481- * const txBytes = buildTransaction({
483+ * const tx = buildTransaction({
482484 * feePayer: sender,
483485 * nonce: { type: 'blockhash', value: blockhash },
484486 * instructions: [
485- * { type: 'transfer', from: sender, to: recipient, lamports: '1000000' }
487+ * { type: 'transfer', from: sender, to: recipient, lamports: 1000000n }
486488 * ]
487489 * });
488490 *
489- * // The returned bytes can be signed and broadcast
491+ * // Inspect the transaction
492+ * console.log(tx.feePayer);
493+ * console.log(tx.recentBlockhash);
494+ *
495+ * // Get the signable payload for signing
496+ * const payload = tx.signablePayload();
497+ *
498+ * // Add signature and serialize
499+ * tx.addSignature(signerPubkey, signature);
500+ * const txBytes = tx.toBytes();
490501 * ```
491502 *
492503 * @example
493504 * ```typescript
494505 * // Build with durable nonce and priority fee
495- * const txBytes = buildTransaction({
506+ * const tx = buildTransaction({
496507 * feePayer: sender,
497508 * nonce: { type: 'durable', address: nonceAccount, authority: sender, value: nonceValue },
498509 * instructions: [
499510 * { type: 'computeBudget', unitLimit: 200000, unitPrice: 5000 },
500- * { type: 'transfer', from: sender, to: recipient, lamports: '1000000' },
511+ * { type: 'transfer', from: sender, to: recipient, lamports: 1000000n },
501512 * { type: 'memo', message: 'BitGo transfer' }
502513 * ]
503514 * });
504515 * ```
505516 */
506- export function buildTransaction ( intent : TransactionIntent ) : Uint8Array {
507- return BuilderNamespace . build_transaction ( intent ) ;
517+ export function buildTransaction ( intent : TransactionIntent ) : Transaction {
518+ const wasm = BuilderNamespace . build_transaction ( intent ) ;
519+ return Transaction . fromWasm ( wasm ) ;
508520}
509521
510522// =============================================================================
@@ -560,17 +572,17 @@ export interface RawVersionedTransactionData {
560572 *
561573 * This function is used for the `fromVersionedTransactionData()` path where we already
562574 * have pre-compiled versioned data (indexes + ALT refs). No instruction compilation
563- * is needed - we just serialize the raw structure to bytes .
575+ * is needed - we just serialize the raw structure.
564576 *
565577 * @param data - Raw versioned transaction data
566- * @returns Serialized unsigned versioned transaction bytes (Uint8Array)
578+ * @returns A VersionedTransaction object that can be inspected, signed, and serialized
567579 * @throws Error if the data is invalid
568580 *
569581 * @example
570582 * ```typescript
571583 * import { buildFromVersionedData } from '@bitgo/wasm-solana';
572584 *
573- * const txBytes = buildFromVersionedData({
585+ * const tx = buildFromVersionedData({
574586 * staticAccountKeys: ['pubkey1', 'pubkey2', ...],
575587 * addressLookupTables: [
576588 * { accountKey: 'altPubkey', writableIndexes: [0, 1], readonlyIndexes: [2] }
@@ -585,8 +597,14 @@ export interface RawVersionedTransactionData {
585597 * },
586598 * recentBlockhash: 'blockhash'
587599 * });
600+ *
601+ * // Inspect, sign, and serialize
602+ * console.log(tx.feePayer);
603+ * tx.addSignature(signerPubkey, signature);
604+ * const txBytes = tx.toBytes();
588605 * ```
589606 */
590- export function buildFromVersionedData ( data : RawVersionedTransactionData ) : Uint8Array {
591- return BuilderNamespace . build_from_versioned_data ( data ) ;
607+ export function buildFromVersionedData ( data : RawVersionedTransactionData ) : VersionedTransaction {
608+ const wasm = BuilderNamespace . build_from_versioned_data ( data ) ;
609+ return VersionedTransaction . fromWasm ( wasm ) ;
592610}
0 commit comments