diff --git a/packages/sats-wagmi/src/connectors/base.ts b/packages/sats-wagmi/src/connectors/base.ts index 7454b04..026c0ab 100644 --- a/packages/sats-wagmi/src/connectors/base.ts +++ b/packages/sats-wagmi/src/connectors/base.ts @@ -210,7 +210,13 @@ abstract class SatsConnector { * const txId = await connector.sendToAddress(toAddress, amount); * ``` */ - abstract sendToAddress(toAddress: string, amount: number): Promise; + async sendToAddress(toAddress: string, amount: number): Promise { + const esploraClient = this.esploraClient; + const signedTx = await this.createAndSignTx(toAddress, amount); + const txId = await esploraClient.broadcastTx(signedTx); + + return txId; + } /** Send BTC to an address with data in an OP_RETURN output * @param toAddress - The address to send BTC to. Can be any valid BTC address. @@ -232,9 +238,7 @@ abstract class SatsConnector { */ async sendToAddressWithOpReturn(toAddress: string, amount: number, data: string): Promise { const esploraClient = this.esploraClient; - - const signedTx = await this.createTxWithOpReturn(toAddress, amount, data); - + const signedTx = await this.createAndSignTx(toAddress, amount, data); const txId = await esploraClient.broadcastTx(signedTx); return txId; @@ -254,9 +258,8 @@ abstract class SatsConnector { * const signedTx = await connector.createTxWithOpReturn(toAddress, amount, data); * ``` */ - async createTxWithOpReturn(toAddress: string, amount: number, data: string): Promise { + async createAndSignTx(toAddress: string, amount: number, data?: string): Promise { this.validatePaymentAddress(); - const psbtBase64 = await createBitcoinPsbt(this.paymentAddress, toAddress, amount, this.publicKey, data); return this.signAllInputs(psbtBase64); diff --git a/packages/sats-wagmi/src/connectors/mm-snap.ts b/packages/sats-wagmi/src/connectors/mm-snap.ts index ba02251..3a54ce3 100644 --- a/packages/sats-wagmi/src/connectors/mm-snap.ts +++ b/packages/sats-wagmi/src/connectors/mm-snap.ts @@ -202,11 +202,6 @@ class MMSnapConnector extends SatsConnector { throw new Error('Not implemented'); } - // FIXME: Refactor using btc-signer - sendToAddress(): Promise { - throw new Error('Method not implemented.'); - } - async signInput(inputIndex: number, psbt: Psbt) { try { const psbtBase64 = await ethereum.request({ diff --git a/playgrounds/vite-react/src/main.tsx b/playgrounds/vite-react/src/main.tsx index 7eecee5..0e6eba3 100644 --- a/playgrounds/vite-react/src/main.tsx +++ b/playgrounds/vite-react/src/main.tsx @@ -1,5 +1,3 @@ -import { Buffer } from 'buffer'; - import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { ReactQueryDevtools } from '@tanstack/react-query-devtools'; import React from 'react'; @@ -8,9 +6,6 @@ import { Network, SatsWagmiConfig } from '@gobob/sats-wagmi'; import './index.css'; -// `@coinbase-wallet/sdk` uses `Buffer` -globalThis.Buffer = Buffer; - import App from './App.tsx'; const queryClient = new QueryClient({