diff --git a/docs/docs/build/bob-sdk/gateway.md b/docs/docs/build/bob-sdk/gateway.md index cf6dd47e..d34d1292 100644 --- a/docs/docs/build/bob-sdk/gateway.md +++ b/docs/docs/build/bob-sdk/gateway.md @@ -93,10 +93,8 @@ 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 * as bitcoin from "bitcoinjs-lib"; import { AddressType, getAddressInfo } from "bitcoin-address-validation"; -import { hex } from "@scure/base"; -import { Transaction as SigTx } from "@scure/btc-signer"; +import { Transaction } from '@scure/btc-signer'; const tx = await createTxWithOpReturn( fromAddress, @@ -111,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) @@ -140,15 +138,10 @@ async function createTxWithOpReturn( opReturn ); const psbt = unsignedTx.toPSBT(0); - const psbtHex = hex.encode(psbt); - const signedPsbtHex = psbtHex; - const signedTx = SigTx.fromPSBT( - bitcoin.Psbt.fromHex(signedPsbtHex).toBuffer() - ); - signedTx.finalize(); - const tx = bitcoin.Transaction.fromBuffer(Buffer.from(signedTx.extract())); - return tx; + const signedTx = Transaction.fromPSBT(psbt); + + return Buffer.from(signedTx.extract()) } ``` diff --git a/sdk/examples/gateway.ts b/sdk/examples/gateway.ts index 1898032b..0941a352 100644 --- a/sdk/examples/gateway.ts +++ b/sdk/examples/gateway.ts @@ -1,9 +1,7 @@ import { GatewayApiClient } from "../src/gateway"; -import * as bitcoin from "bitcoinjs-lib"; import { AddressType, getAddressInfo } from "bitcoin-address-validation"; import { createTransfer } from "../src/wallet/utxo"; -import { hex } from '@scure/base'; -import { Transaction as SigTx } from '@scure/btc-signer'; +import { Transaction } from '@scure/btc-signer'; const BOB_TBTC_V2_TOKEN_ADDRESS = "0xBBa2eF945D523C4e2608C9E1214C2Cc64D4fc2e2"; @@ -25,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,13 +49,8 @@ async function createTxWithOpReturn(fromAddress: string, toAddress: string, amou ); const psbt = unsignedTx.toPSBT(0); - const psbtHex = hex.encode(psbt); - // TODO: sign PSBT - const signedPsbtHex = psbtHex; + const signedTx = Transaction.fromPSBT(psbt); - const signedTx = SigTx.fromPSBT(bitcoin.Psbt.fromHex(signedPsbtHex).toBuffer()); - signedTx.finalize(); - - return bitcoin.Transaction.fromBuffer(Buffer.from(signedTx.extract())); + return Buffer.from(signedTx.extract()) }