🔴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 parametersDescription

transaction

a hex-encoded string representing the Stacks transaction to sign

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 { Wallet } 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 Wallet.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 Wallet.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 Wallet.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 calll 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:

PropertyDescription

transaction

a hex-encoded string reperesenting the transfer STX transaction signed