From 25fcfa5c6289277910b9cffbdf40fc4e74af94c9 Mon Sep 17 00:00:00 2001 From: nakul1010 Date: Tue, 13 Aug 2024 18:07:29 +0530 Subject: [PATCH] fix: return serialized signed transaction --- docs/docs/build/bob-sdk/gateway.md | 10 ++++++---- sdk/examples/gateway.ts | 9 +++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/docs/docs/build/bob-sdk/gateway.md b/docs/docs/build/bob-sdk/gateway.md index 20d5067e..d34d1292 100644 --- a/docs/docs/build/bob-sdk/gateway.md +++ b/docs/docs/build/bob-sdk/gateway.md @@ -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, @@ -110,7 +109,7 @@ async function createTxWithOpReturn( amount: number, opReturn: string, fromPubKey?: string -): Promise { +): Promise { const addressType = getAddressInfo(fromAddress).type; // Ensure this is not the P2TR address for ordinals (we don't want to spend from it) @@ -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()) } ``` diff --git a/sdk/examples/gateway.ts b/sdk/examples/gateway.ts index 2ec1fad7..0941a352 100644 --- a/sdk/examples/gateway.ts +++ b/sdk/examples/gateway.ts @@ -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"; @@ -24,7 +23,7 @@ export async function swapBtcForToken(evmAddress: string) { } -async function createTxWithOpReturn(fromAddress: string, toAddress: string, amount: number, opReturn: string, fromPubKey?: string): Promise { +async function createTxWithOpReturn(fromAddress: string, toAddress: string, amount: number, opReturn: string, fromPubKey?: string): Promise { const addressType = getAddressInfo(fromAddress).type; // Ensure this is not the P2TR address for ordinals (we don't want to spend from it) @@ -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()) }