Skip to main content

Checking if a wallet is a Solana wallet

  • React
  • React Native
  • JavaScript
React
import { isSolanaWallet } from '@dynamic-labs/solana';

if (!isSolanaWallet(wallet)) {
  throw new Error('This wallet is not a Solana wallet');
}

Get Connection

  • React
  • React Native
  • JavaScript
React
import { useUserWallets } from '@dynamic-labs/sdk-react-core';
import { isSolanaWallet } from '@dynamic-labs/solana';

const wallets = useUserWallets();

const connection = wallets.find(wallet => isSolanaWallet(wallet))?.getConnection();

Get Signer

  • React
  • React Native
  • JavaScript
React
import { useUserWallets } from '@dynamic-labs/sdk-react-core';
import { isSolanaWallet } from '@dynamic-labs/solana';

const wallets = useUserWallets();

const signer = wallets.find(wallet => isSolanaWallet(wallet))?.getSigner();

Custom Connection (React only)

In some cases you would want to override the default settings of the Web3.js Connection. React provides the SolanaWalletConnectorsWithConfig to customize Web3.js Connection configuration with commitment levels, HTTP headers, and custom RPC URLs.
React
import { DynamicContextProvider } from '@dynamic-labs/sdk-react-core';
import { SolanaWalletConnectorsWithConfig } from '@dynamic-labs/solana';

<DynamicContextProvider
  settings={{
    walletConnectors: [
      SolanaWalletConnectorsWithConfig({
        commitment: "confirmed",
        httpHeaders: {
          "X-Requested-With": "XMLHttpRequest",
        },
        customRpcUrls: {
          solana: ["http://YOUR_URL"],
          eclipse: ["http://YOUR_URL"],
        },
      }),
    ],
    ... // other settings
  }}
>
  {...}
</DynamicContextProvider>

Examples

You can find examples of how to interact with Solana wallets in the examples section:
I