> For the complete documentation index, see [llms.txt](https://comet-3.gitbook.io/comet-sdk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://comet-3.gitbook.io/comet-sdk/reference/comet-sdk-reference/comet-react-sdk/hooks/usesigntransaction.md).

# useSignTransaction

Since Comet accounts come with a built-in cloud wallet, you can use this wallet to provide a signature for any Solana transaction using the `useSignTransaction` hook. The user will be prompted to log in if necessary, and will be asked to confirm the transaction to be signed (similar to the flow for Metamask or Phantom wallets).

<figure><img src="/files/hK8UH9LtFTO5X4WBcBDy" alt=""><figcaption></figcaption></figure>

## API

```javascript
const { signTransaction } = useSignTransaction({ transaction: TRANSACTION });
```

In the example above, `TRANSACTION` is a `Transaction` object generated by the Solana Web3 library (see [`@solana/web3.js`](https://docs.solana.com/developing/clients/javascript-api)).

`signTransaction` is a function that can be called later on, which brings up a confirmation dialog. When the user clicks "Sign", the transaction is partially signed by the private key in the user's Comet wallet. Keep in mind that if the transaction requires additional signatures, those will need to be provided separately.

`signTransaction` returns a successful `Promise` containing the `Transaction` object with the added signature, or a failed `Promise` if the user clicks "Cancel".

## Example

```tsx
import { useAccount, useSignTransaction } from '@comet-labs/react';
import { PublicKey, Transaction, SystemProgram } from '@solana/web3.js';

function App() {
  const account = useAccount();

  return (
    <div className="App">
      {
        account && <SignTransactionButton account={account} />
      }
    </div>
  );
}

function SignTransactionButton(props) {
  const tx = new Transaction().add(
    SystemProgram.transfer({
      fromPubkey: new PublicKey(props.account.address),
      toPubkey: new PublicKey('Dgq5B8i5NJJfPoUgpkFZDzRr84zd1BJrUBntJt1EBvgd'),
      lamports: 2000000,
    })
  );

  const { signTransaction } = useSignTransaction({ transaction: tx });

  return (
    <button onClick={signTransaction} className='bg-gray-800 text-white p-4 rounded-full'>
      sign transaction! &#x1F389;
    </button>
  );
}
```
