Skip to content

Commit eba962b

Browse files
committed
feat(wasm-solana): add Transaction.toBroadcastFormat()
Add toBroadcastFormat() method to Transaction and VersionedTransaction. Returns base64 encoded transaction for Solana network broadcast. Ticket: BTC-3002
1 parent b406540 commit eba962b

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

packages/wasm-solana/js/transaction.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ export class Transaction {
131131
return this._wasm.to_bytes();
132132
}
133133

134+
/**
135+
* Serialize to network broadcast format.
136+
* @returns The transaction as bytes ready for broadcast
137+
*/
138+
toBroadcastFormat(): Uint8Array {
139+
return this.toBytes();
140+
}
141+
134142
/**
135143
* Get all account keys as Pubkey instances
136144
* @returns Array of account public keys

packages/wasm-solana/js/versioned.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,14 @@ export class VersionedTransaction {
209209
return Buffer.from(this.toBytes()).toString("base64");
210210
}
211211

212+
/**
213+
* Serialize to network broadcast format.
214+
* @returns The transaction as bytes ready for broadcast
215+
*/
216+
toBroadcastFormat(): Uint8Array {
217+
return this.toBytes();
218+
}
219+
212220
/**
213221
* Get static account keys (accounts stored directly in the message).
214222
* For versioned transactions, additional accounts may be referenced via ALTs.

packages/wasm-solana/test/versioned.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,15 @@ describe("VersionedTransaction", () => {
9595

9696
describe("id getter", () => {
9797
it("should return UNSIGNED for unsigned transaction", () => {
98-
const tx = VersionedTransaction.fromBase64(LEGACY_TX_BASE64);
98+
const bytes = Buffer.from(LEGACY_TX_BASE64, "base64");
99+
const tx = VersionedTransaction.fromBytes(bytes);
99100
// The test transaction has an all-zeros signature (unsigned)
100101
assert.strictEqual(tx.id, "UNSIGNED");
101102
});
102103

103104
it("should return base58 signature after signing", () => {
104-
const tx = VersionedTransaction.fromBase64(LEGACY_TX_BASE64);
105+
const bytes = Buffer.from(LEGACY_TX_BASE64, "base64");
106+
const tx = VersionedTransaction.fromBytes(bytes);
105107
const feePayer = tx.feePayer;
106108

107109
// Add a non-zero signature

0 commit comments

Comments
 (0)