# 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.

<table><thead><tr><th width="200">Request parameters</th><th>Description</th></tr></thead><tbody><tr><td><code>transaction</code></td><td>a hex-encoded string representing the  Stacks transaction to sign </td></tr><tr><td><code>broadcast</code><br>(<span data-gb-custom-inline data-tag="emoji" data-code="2139">ℹ️</span> optional)</td><td>a boolean flag that specifies whether to broadcast the signed transaction after signature. Defaults to <code>TRUE</code></td></tr></tbody></table>

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

```typescript
    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&#x20;
* sign a contract deployment transaction

The user will see a Stacks transaction signing request prompt in the wallet. Xverse browser extension UI shown as example for a token transfer:\
\
![](https://content.gitbook.com/content/33DLypUqgcjkBSmN0gZn/blobs/JbbTV2jm8ISyE2nrrObE/image.png)

The transaction will be signed and broadcasted upon user approval.

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

<table><thead><tr><th width="162">Property</th><th>Description</th></tr></thead><tbody><tr><td><code>transaction</code></td><td>a hex-encoded string representing the transaction signed</td></tr></tbody></table>
