Sats Connect - Wallet API for Bitcoin & Stacks
  • Introduction
  • Wallet Providers
    • getInfo
    • getProviders & getProviderById
  • Connecting to the wallet
    • Connect to Xverse Wallet
    • Disconnect from Xverse Wallet
    • Connect to other wallets
      • Manage a user's default wallet
    • [Legacy âš ī¸] getAccounts
  • Wallet Methods
    • request methods
    • wallet_getAccount
    • wallet_getNetwork
    • wallet_changeNetwork
    • Xverse Custom Methods
  • Xverse Wallet Permissions
  • Xverse Wallet events
  • BITCOIN METHODS
    • 🟠getAddresses
    • 🟠signMessage
    • 🟠signPsbt
    • 🟠sendTransfer
    • 🟠signMultipleTransactions
    • 🟠getBalance
    • 🎨createInscription
    • 🎨createRepeatInscriptions
    • 🎨ord_getInscriptions
    • 🎨ord_sendInscriptions
    • 🔲runes_getBalance
    • 🔲runes_transfer
    • 🔲Mint Runes
      • runes_estimateMint
      • runes_mint
    • 🔲Etch Runes
      • runes_estimateEtch
      • runes_etch
    • 🔲runes_getOrder
    • 🔲Speed up a Rune Mint or Etch order
      • 🔲runes_estimateRbfOrder
      • 🔲runes_rbfOrder
  • STACKS METHODS
    • 🔴stx_getAccounts
    • 🔴stx_signMessage
    • 🔴stx_signStructuredMessage
    • 🔴stx_transferStx
    • 🔴stx_signTransaction
    • 🔴stx_callContract
    • 🔴stx_deployContract
  • GUIDES
    • Verify Bitcoin message signatures
    • Creating Bitcoin PSBTs
    • 📱Mobile Integration
    • Next.js support
  • RESOURCES
    • App Template
    • Demo App
    • Changelog
    • Github Issues
    • Developer forum
    • BIP322
Powered by GitBook
On this page
  1. STACKS METHODS

stx_signTransaction

You can use the stx_signTransaction method to request the signature of any hex-encoded Stacks transaction from your user's Stacks wallet address.

Request parameters
Description

transaction

a hex-encoded string representing the Stacks transaction to sign

a boolean flag that specifies whether to broadcast the signed transaction after signature. Defaults to TRUE

You can use any Stacks library to construct these transaction. See examples using helpers from the @stacks/transactions package

    import {
       makeUnsignedContractCall,
       makeUnsignedContractDeploy,
       makeUnsignedSTXTokenTransfer,
       uintCV,
     } from "@stacks/transactions";
    import { request } from "sats-connect";

    //contract call transaction   
const transaction = await makeUnsignedContractCall({
      fee: 3000,
      anchorMode: "onChainOnly",
      contractAddress: "SP21YTSM60CAY6D011EZVEVNKXVW8FVZE198XEFFP",
      contractName: "pox-fast-pool-v2",
      functionName: "set-stx-buffer",
      functionArgs: [uintCV(1)],
      publicKey: props.publicKey,
    });
    try {
      const response = await request("stx_signTransaction", {
        transaction: uint8ArrayToHex(transaction.serialize()),
      });
      if (response.status === "success") {
        console.log(response.result.transaction);
      } else {
        alert(errorMessage);
        console.error(response.error);
      }
    } catch (error) {
      alert(errorMessage);
      console.error(error);

//token transfer transaction 
    const transaction = await makeUnsignedSTXTokenTransfer({
      anchorMode: "any",
      fee: 3000,
      recipient: "SP2FFKDKR122BZWS7GDPFWC0J0FK4WMW5NPQ0Z21M", // account 4
      amount: 1000,
      publicKey: props.publicKey,
    });
    try {
      const response = await request("stx_signTransaction", {
        transaction: uint8ArrayToHex(transaction.serialize()),
      });
      if (response.status === "success") {
        console.log(response.result.transaction);
      } else {
        alert(errorMessage);
        console.error(response.error);
      }
    } catch (error) {
      alert(errorMessage);
      console.error(error);
    }


//contract deployment transaction 
    const transaction = await makeUnsignedContractDeploy({
      anchorMode: "any",
      contractName: "my-contract",
      codeBody: code,
      fee: 3000,
      publicKey: props.publicKey,
    });
    try {
      const response = await request("stx_signTransaction", {
        transaction: uint8ArrayToHex(transaction.serialize()),
      });
      if (response.status === "success") {
        console.log(response.result.transaction);
      } else {
        alert(errorMessage);
        console.error(response.error);
      }
    } catch (error) {
      alert(errorMessage);
      console.error(error);
    }

The above request examples will ask the wallet to:

  • sign a contract call transaction

  • sign a token transfer request

  • sign a contract deployment transaction

The transaction will be signed and broadcasted upon user approval.

The stx_signTransaction method returns a Promise that resolves to the SignTransactionResult object:

Property
Description

transaction

a hex-encoded string representing the transaction signed

Previousstx_transferStxNextstx_callContract

Last updated 5 months ago

broadcast ( optional)

The user will see a Stacks transaction signing request prompt in the wallet. Xverse browser extension UI shown as example for a token transfer:

🔴
â„šī¸