Skip to content

Commit

Permalink
fix: return serialized signed transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
nakul1010 committed Aug 13, 2024
1 parent 7a39a22 commit 25fcfa5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
10 changes: 6 additions & 4 deletions docs/docs/build/bob-sdk/gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ We recommend using our [sats-wagmi](./sats-wagmi.md) package to query your user'
```ts title="/src/utils/gateway.ts"
import { createTransfer } from "@gobob/bob-sdk";
import { AddressType, getAddressInfo } from "bitcoin-address-validation";
import { hex, base64 } from "@scure/base";
import { Transaction as SigTx } from "@scure/btc-signer";
import { Transaction } from '@scure/btc-signer';

const tx = await createTxWithOpReturn(
fromAddress,
Expand All @@ -110,7 +109,7 @@ async function createTxWithOpReturn(
amount: number,
opReturn: string,
fromPubKey?: string
): Promise<base64> {
): Promise<Buffer> {
const addressType = getAddressInfo(fromAddress).type;

// Ensure this is not the P2TR address for ordinals (we don't want to spend from it)
Expand Down Expand Up @@ -139,7 +138,10 @@ async function createTxWithOpReturn(
opReturn
);
const psbt = unsignedTx.toPSBT(0);
return base64.encode(psbt)

const signedTx = Transaction.fromPSBT(psbt);

return Buffer.from(signedTx.extract())
}
```

Expand Down
9 changes: 5 additions & 4 deletions sdk/examples/gateway.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { GatewayApiClient } from "../src/gateway";
import { AddressType, getAddressInfo } from "bitcoin-address-validation";
import { createTransfer } from "../src/wallet/utxo";
import { hex, base64 } from '@scure/base';
import { Transaction as SigTx } from '@scure/btc-signer';
import { Transaction } from '@scure/btc-signer';

const BOB_TBTC_V2_TOKEN_ADDRESS = "0xBBa2eF945D523C4e2608C9E1214C2Cc64D4fc2e2";

Expand All @@ -24,7 +23,7 @@ export async function swapBtcForToken(evmAddress: string) {

}

async function createTxWithOpReturn(fromAddress: string, toAddress: string, amount: number, opReturn: string, fromPubKey?: string): Promise<base64> {
async function createTxWithOpReturn(fromAddress: string, toAddress: string, amount: number, opReturn: string, fromPubKey?: string): Promise<Buffer> {
const addressType = getAddressInfo(fromAddress).type;

// Ensure this is not the P2TR address for ordinals (we don't want to spend from it)
Expand All @@ -51,5 +50,7 @@ async function createTxWithOpReturn(fromAddress: string, toAddress: string, amou

const psbt = unsignedTx.toPSBT(0);

return base64.encode(psbt)
const signedTx = Transaction.fromPSBT(psbt);

return Buffer.from(signedTx.extract())
}

0 comments on commit 25fcfa5

Please sign in to comment.