> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dynamic.xyz/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# signTransaction (Stellar)

# signTransaction

Signs a Stellar transaction XDR using the connected wallet. The wallet provider handles the actual signing via its native API (e.g. Freighter, Lobstr, OneKey).

## Usage

```javascript theme={"system"}
import { signTransaction, isStellarWalletAccount } from '@dynamic-labs-sdk/stellar';
import { getPrimaryWalletAccount } from '@dynamic-labs-sdk/client';

const walletAccount = getPrimaryWalletAccount();

if (walletAccount && isStellarWalletAccount(walletAccount)) {
  const { signedXdr } = await signTransaction({
    transactionXdr: 'AAAA...', // base64-encoded transaction envelope
    walletAccount,
  });

  console.log('Signed XDR:', signedXdr);
}
```

## Building a Transaction XDR

Use the `@stellar/stellar-sdk` to build a transaction before signing:

```javascript theme={"system"}
import {
  TransactionBuilder,
  Operation,
  Asset,
  BASE_FEE,
  Horizon,
  Networks,
} from '@stellar/stellar-sdk';
import { signTransaction, isStellarWalletAccount } from '@dynamic-labs-sdk/stellar';
import { getPrimaryWalletAccount } from '@dynamic-labs-sdk/client';

const walletAccount = getPrimaryWalletAccount();

if (walletAccount && isStellarWalletAccount(walletAccount)) {
  const server = new Horizon.Server('https://horizon.stellar.org');
  const sourceAccount = await server.loadAccount(walletAccount.address);

  const transaction = new TransactionBuilder(sourceAccount, {
    fee: BASE_FEE,
    networkPassphrase: Networks.PUBLIC,
  })
    .addOperation(
      Operation.payment({
        destination: 'GDEST...',
        asset: Asset.native(),
        amount: '10',
      })
    )
    .setTimeout(180)
    .build();

  const { signedXdr } = await signTransaction({
    transactionXdr: transaction.toXDR(),
    walletAccount,
  });
}
```

## Parameters

| Parameter        | Type                   | Description                                                                               |
| ---------------- | ---------------------- | ----------------------------------------------------------------------------------------- |
| `transactionXdr` | `string`               | The base64-encoded transaction envelope XDR to sign                                       |
| `walletAccount`  | `StellarWalletAccount` | The wallet account to sign the transaction with                                           |
| `client`         | `DynamicClient`        | (optional) The Dynamic client instance. Only required when using multiple Dynamic clients |

## Returns

`Promise<{ signedXdr: string }>` - A promise that resolves to an object containing the signed transaction XDR.

## Errors

| Error                     | Description                                                       |
| ------------------------- | ----------------------------------------------------------------- |
| `NotStellarProviderError` | Thrown if the wallet account's provider is not a Stellar provider |

## React

```tsx theme={"system"}
import { signTransaction, isStellarWalletAccount } from '@dynamic-labs-sdk/stellar';
import { useWalletAccounts } from '@dynamic-labs-sdk/react-hooks';
import { useState } from 'react';

function StellarSignButton({ transactionXdr }) {
  const walletAccounts = useWalletAccounts();
  const walletAccount = walletAccounts.find(isStellarWalletAccount);
  const [signedXdr, setSignedXdr] = useState('');

  const handleSign = async () => {
    if (!walletAccount) return;

    const { signedXdr } = await signTransaction({
      transactionXdr,
      walletAccount,
    });

    setSignedXdr(signedXdr);
  };

  return (
    <div>
      <button onClick={handleSign} disabled={!walletAccount}>
        Sign Transaction
      </button>
      {signedXdr && <p>Signed</p>}
    </div>
  );
}
```

## Related functions

* [addStellarExtension](/javascript/reference/stellar/adding-stellar-extension) - Add Stellar support to your client
* [isStellarWalletAccount](/javascript/reference/stellar/checking-stellar-wallet-account-type) - Check if a wallet account is a Stellar account
