Skip to content

Docs request: WalletSession -> TransactionSigner adapter for Codama / @solana/kit #151

Description

@Vishwa9011

Summary

When using @solana/react-hooks (as in create-solana-dapp), the wallet connection
exposes a WalletSession, but Codama-generated instructions require a
TransactionSigner. There’s no documented/official way to adapt a
WalletSession to a TransactionSigner.

Problem to solve

Current behavior

  • useWalletSession() returns a WalletSession with signTransaction and/or sendTransaction.
  • Codama instructions (e.g. getInitializeFactoryInstructionAsync) require a TransactionSigner.
  • There’s a helper in @solana/client (src/signers/walletTransactionSigner.ts),
    but it is not exported from the public package exports, so it can’t be imported.
  • Result: apps end up writing ad-hoc adapters.

Expected behavior

Provide official documentation (or export a helper) that shows how to get a
TransactionSigner from a WalletSession to support Codama/kit-generated
instructions.

Proposed docs addition

Example adapter that supports either signTransaction or sendTransaction:

import { getBase58Encoder } from "@solana/codecs-strings";
import { signatureBytes } from "@solana/keys";
import type { SendableTransaction, Transaction } from "@solana/transactions";
import type {
  TransactionPartialSigner,
  TransactionSendingSigner,
  TransactionSigner,
} from "@solana/kit";
import type { WalletSession } from "@solana/client";

const base58 = getBase58Encoder();

function toSendable(tx: Transaction): SendableTransaction & Transaction {
  return tx as SendableTransaction & Transaction;
}

export function walletSessionToSigner(session: WalletSession): TransactionSigner {
  if (session.signTransaction) {
    const signer: TransactionPartialSigner = {
      address: session.account.address,
      signTransactions: async (txs) => {
        const signed = await Promise.all(
          txs.map((tx) => session.signTransaction!(toSendable(tx))),
        );
        return signed.map((tx) => ({
          [session.account.address]: tx.signatures[session.account.address],
        }));
      },
    };
    return signer;
  }

  if (session.sendTransaction) {
    const signer: TransactionSendingSigner = {
      address: session.account.address,
      signAndSendTransactions: async (txs) => {
        const sigs = await Promise.all(
          txs.map((tx) => session.sendTransaction!(toSendable(tx))),
        );
        return sigs.map((sig) => signatureBytes(base58.encode(sig)));
      },
    };
    return signer;
  }

  throw new Error("Wallet does not support transaction signing.");
}


Alternatively, please export the existing helper
createWalletTransactionSigner from @solana/client so apps don’t need to roll
their own adapter.

Why this matters
Codama + kit is the official path for program clients, but the primary starter
template uses @solana/react-hooks. Without a documented bridge, developers hit
a confusing gap on day one.

### Proposed solution

Alternatively, please export the existing helper
createWalletTransactionSigner from @solana/client so apps don’t need to roll
their own adapter.

### Alternatives considered

_No response_

### Additional context

_No response_

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions