secretkeylabs / sats-connect

Sats connect is a simple javascript library that connects apps to Bitcoin wallets
https://www.npmjs.com/package/sats-connect
82 stars 33 forks source link

The transaction couldn’t proceed Request failed with status code 400 #125

Open vendersen opened 1 month ago

vendersen commented 1 month ago

Is there an existing issue for this?

SATS-CONNECT Version

2.2.2

Current Behavior

When I use the sats-connect api to build a sending transaction, the receiving address is TapRoot, and Xverse.app keeps prompting The transaction couldn’t proceed Request failed with status code 400,

Expected Behavior

Transaction broadcast successful

Steps To Reproduce

1 2

Link to Minimal Reproducible Example (CodeSandbox, StackBlitz, etc.)

No response

Anything else?

No response

vendersen commented 1 month ago

There is no problem with the Google Chrome plug-in wallet, I think it may be caused by the mobile wallet

vendersen commented 1 month ago
import {
    getProviders,
    getProviderById
} from 'sats-connect'

var Wallet = null
var walletAddr = null

export default {
    async Connect() {
        try {
            const providers = getProviders();

            const firstProvider = providers[0];

            Wallet = getProviderById(firstProvider.id);
            // 连接钱包
            const result = await Wallet.request('getAccounts', {
                purposes: ['payment','ordinals'],
                message: 'Address for receiving payments'
            });

            if (result.result) {
                if (result.result.length > 0) {
                    walletAddr = result.result[0].address
                    return walletAddr
                }
            }

            if (result.error) {
                throw new Error(result.error.message)
            }

        } catch (e) {
            //TODO handle the exception
            throw e
        }
    },
    GetAccount() {
        return walletAddr
    },
    async Send(recipient, amount) {
        try {
            // 发送比特币
            const result = await Wallet.request("sendTransfer", {
                recipients: [{
                    address: recipient,
                    amount: Number(amount),
                }]
            });
            if (result.result) {
                return result.result.txid
            }
            if (result.error) {
                throw new Error(result.error.message)
            }

        } catch (e) {
            throw e
        }

    }
}
fedeerbes commented 1 month ago

hi @vendersen, thanks for letting us know. i'll take a look and let you know as soon as i have an answer.

fedeerbes commented 1 month ago

hi @vendersen. i'm not able to reproduce this issue, i'm using mobile app version 1.30.1 and sats-connect 2.2.2. are you able to repro this issue consistently in latest mobile app version 1.30.1?