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

# Integrating with @solana/kit

<View title="React" icon="react">
  Privy's **ConnectedStandardSolanaWallet** object is fully compatible with popular web3 libraries for interfacing wallets and signing transactions and messages, such as [`@solana/kit`](https://www.solanakit.com/).

  Read below to learn how to best integrate Privy alongside `@solana/kit`.

  First find your desired wallet from the **`wallets`** array:

  ```tsx theme={"system"}
  import {useWallets} from '@privy-io/react-auth/solana';

  const {wallets} = useWallets();
  const wallet = wallets[0]; // Replace this with your desired wallet
  ```

  ## Signing Transactions

  Transactions generated by `@solana/kit` can be signed using the `signTransaction` method from the `useStandardSignTransaction` hook.

  ```tsx theme={"system"}
  import {
    pipe,
    createTransactionMessage,
    setTransactionMessageFeePayer,
    setTransactionMessageLifetimeUsingBlockhash,
    appendTransactionMessageInstructions,
    compileTransaction,
    createNoopSigner,
    createSolanaRpc,
    getTransactionEncoder
  } from '@solana/kit';
  import {getTransferSolInstruction} from '@solana-program/system';
  import {useStandardSignTransaction} from '@privy-io/react-auth/solana';

  const {signTransaction} = useStandardSignTransaction();

  const LAMPORTS_PER_SOL = 1_000_000_000;

  const transferInstruction = getTransferSolInstruction({
    amount: LAMPORTS_PER_SOL * 1,
    destination: address(to),
    source: createNoopSigner(address(wallet.address))
  });

  const {getLatestBlockhash} = createSolanaRpc('YOUR_SOLANA_RPC_URL');
  const {value: latestBlockhash} = await getLatestBlockhash().send();

  // Create transaction
  const transaction = pipe(
    createTransactionMessage({version: 0}),
    (tx) => setTransactionMessageFeePayer(address(wallet.address), tx),
    (tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx),
    (tx) => appendTransactionMessageInstructions([transferInstruction], tx),
    (tx) => compileTransaction(tx)
  );
  const encodedTransaction = getTransactionEncoder().encode(transaction);

  // Sign the transaction
  const signedTransaction = await signTransaction({
    transaction: new Uint8Array(encodedTransaction),
    wallet: wallet
  });
  ```

  ## Sending Transactions

  Transactions signed using the `signTransaction` method can be sent using the `signAndSendTransaction` method from the `useStandardSignAndSendTransaction` hook.

  <Info>
    Some external wallets connected via `wallet_connect_qr_solana` (such as Fireblocks) only support
    signing and do not support sign-and-send. For these wallets, `signTransaction` returns a raw
    64-byte signature instead of a fully signed transaction. See the [sign a
    transaction](/wallets/using-wallets/solana/sign-a-transaction) guide for instructions on how to
    attach the signature to the compiled transaction and send it manually.
  </Info>

  ```tsx theme={"system"}
  import {useStandardSignAndSendTransaction} from '@privy-io/react-auth/solana';

  const {signAndSendTransaction} = useStandardSignAndSendTransaction();

  const signature = await signAndSendTransaction({
    transaction: new Uint8Array(transaction), // The transaction to send, from the previous example
    wallet: wallet
  }).signature;
  ```
</View>

<View title="NodeJS" icon="node-js">
  Privy's wallets on Solana natively integrate with `@solana/kit` via the
  `@privy-io/node` SDK, allowing you to use the library's signer interfaces for
  signing messages and transactions, as well as sending those transactions to the
  blockchain.

  ## Setup

  To integrate with `@solana/kit`, first install the library as a peer dependency:

  ```sh theme={"system"}
  npm i @solana/kit
  ```

  Then, use Privy's `createSolanaKitSigner` method to initialize a signer for a Solana
  wallet.
  To this method, pass the following fields:

  <ParamField body="walletId" type="string" required>
    The ID of the wallet to sign with.
  </ParamField>

  <ParamField body="address" type="string" required>
    The address of the wallet to sign with.
  </ParamField>

  <ParamField body="authorizationContext" type="object">
    The authorization context for the wallet. Refer to the [authorization
    context](/controls/authorization-context) guide for more details.
  </ParamField>

  <ParamField body="caip2" type="string">
    The CAIP-2 identifier for the Solana network. This is only required when sending transactions with
    the Signer.
  </ParamField>

  ### Example usage

  As an example, you can initialize a signer like so:

  ```ts theme={"system"}
  import {PrivyClient} from '@privy-io/node';
  import {createSolanaKitSigner} from '@privy-io/node/solana-kit';
  import {address} from '@solana/kit';

  // Set up the Privy client and signer
  const privy = new PrivyClient({appId: 'your-app-id', appSecret: 'your-app-secret'});
  const signer = createSolanaKitSigner(privy, {
    walletId: 'insert-wallet-id',
    address: address('insert-wallet-address')
  });
  ```

  <Tip>
    If your wallet requires an [authorization context](/controls/authorization-context),
    you should pass it to the `createSolanaKitSigner` method like so, and it will be used
    throughout the lifetime of the signer:

    ```ts theme={"system"}
    import {PrivyClient} from '@privy-io/node';
    import {createSolanaKitSigner} from '@privy-io/node/solana-kit';
    import {address} from '@solana/kit';

    // Set up the Privy client and signer
    const privy = new PrivyClient({appId: 'your-app-id', appSecret: 'your-app-secret'});
    const signer = createSolanaKitSigner(privy, {
      walletId: 'insert-wallet-id',
      address: address('insert-wallet-address'),
      authorizationContext: {
        authorization_private_keys: ['authorization-key']
      }
    });
    ```
  </Tip>

  ## Signing messages

  You can sign messages using helper functions provided by `@solana/kit`, or by calling the `signMessages` method directly:

  <CodeGroup>
    ```ts Ergonomic theme={"system"}
    import {PrivyClient} from '@privy-io/node';
    import {createSolanaKitSigner} from '@privy-io/node/solana-kit';
    import {address, signOffchainMessageWithSigners, type OffchainMessage} from '@solana/kit';

    // Set up the Privy client and signer
    const privy = new PrivyClient({appId: 'your-app-id', appSecret: 'your-app-secret'});
    const signer = createSolanaKitSigner(privy, {
      walletId: 'insert-wallet-id',
      address: address('insert-wallet-address')
    });

    const offchainMessage: OffchainMessage = {
      version: 1,
      content: 'Hello, world!',
      requiredSignatories: [signer]
    };
    const signedEnvelope = await signOffchainMessageWithSigners(offchainMessage);
    ```

    ```ts Direct theme={"system"}
    import {PrivyClient} from '@privy-io/node';
    import {createSolanaKitSigner} from '@privy-io/node/solana-kit';
    import {address, createSignableMessage} from '@solana/kit';

    // Set up the Privy client and signer
    const privy = new PrivyClient({appId: 'your-app-id', appSecret: 'your-app-secret'});
    const signer = createSolanaKitSigner(privy, {
      walletId: 'insert-wallet-id',
      address: address('insert-wallet-address')
    });

    const message = createSignableMessage('Hello, world!');
    const signatures = await signer.signMessages([message]);
    ```
  </CodeGroup>

  ## Signing transactions

  You can sign transactions using `@solana/kit`'s transaction building utilities:

  ```ts theme={"system"}
  import {PrivyClient} from '@privy-io/node';
  import {createSolanaKitSigner} from '@privy-io/node/solana-kit';
  import {
    address,
    createTransactionMessage,
    pipe,
    setTransactionMessageFeePayerSigner,
    signTransactionMessageWithSigners
  } from '@solana/kit';

  // Set up the Privy client and signer
  const privy = new PrivyClient({appId: 'your-app-id', appSecret: 'your-app-secret'});
  const signer = createSolanaKitSigner(privy, {
    walletId: 'insert-wallet-id',
    address: address('insert-wallet-address')
  });

  const transactionMessage = pipe(
    createTransactionMessage({version: 0}),
    // This sets both the fee payer address *and* uses the underlying signer.
    (m) => setTransactionMessageFeePayerSigner(signer, m)
    // Add instructions, lifetime, etc.
  );

  const signedTransaction = await signTransactionMessageWithSigners(transactionMessage);
  ```

  ## Signing and sending transactions

  To sign and send transactions, you must provide the `caip2` parameter when creating the signer:

  ```ts theme={"system"}
  import {PrivyClient} from '@privy-io/node';
  import {createSolanaKitSigner} from '@privy-io/node/solana-kit';
  import {
    address,
    createTransactionMessage,
    pipe,
    setTransactionMessageFeePayerSigner,
    signAndSendTransactionMessageWithSigners
  } from '@solana/kit';

  // Set up the Privy client and signer
  const privy = new PrivyClient({appId: 'your-app-id', appSecret: 'your-app-secret'});
  const signer = createSolanaKitSigner(privy, {
    walletId: 'insert-wallet-id',
    address: address('insert-wallet-address'),
    caip2: 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1' // Solana Devnet
  });

  // The signer can now be used with signAndSendTransactionMessageWithSigners
  const transactionMessage = pipe(
    createTransactionMessage({version: 0}),
    (m) => setTransactionMessageFeePayerSigner(signer, m)
    // Add instructions, lifetime, etc.
  );

  const signedTransaction = await signAndSendTransactionMessageWithSigners(transactionMessage);
  ```

  <Tip>
    Common CAIP-2 identifiers for Solana:

    * Mainnet: `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp`
    * Testnet: `solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z`
    * Devnet: `solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1`
  </Tip>
</View>
