Unable to get privateKey from Solana Chain using "solanaPrivateKey" method

When asking for help in this category, please make sure to provide the following details:

  • SDK Version(package.json):
    @web3auth/base”: “^9.0.0”,
    @web3auth/ethereum-provider”: “^9.0.0”,
    @web3auth/modal”: “^10.0.5”,
    @web3auth/solana-provider”: “^9.7.0”,

  • Platform: ReactJS in web browser

  • Browser Console Screenshots:

  • My code config:

const web3AuthContextConfig = {
  web3AuthOptions: {
    clientId: 'BE9SGsntpxv6Utr9Z0uYFJZKocyXejbUhgvwmqg5_he_RcxUMREfJtRssunMqmpwG8HloKMEEctsgkNNfj0YBnc',
    defaultChainId: '0x67',
    web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_DEVNET,
    uiConfig: {
      mode: 'dark',
      defaultLanguage: language,
      borderRadiusType: 'medium',
      displayInstalledExternalWallets: false,
      displayExternalWalletsCount: false,
    },
    modalConfig: {
      connectors: {
        [WALLET_CONNECTORS.AUTH]: {
          label: 'auth',
          loginMethods: {
            google: {
              name: 'Google',
              showOnModal: true,
              authConnectionId: 'w3a-google-bth',
            },
            email_passwordless: {
              name: 'Email',
              showOnModal: true,
              authConnectionId: 'w3a-email-btn',
            },
            apple: {
              name: 'Apple',
              showOnModal: true,
            },
          },
          showOnModal: true,
        },
        [WALLET_CONNECTORS.METAMASK]: {
          label: 'metamask',
          showOnModal: false,
        },
      },
      hideWalletDiscovery: true,
    },
  },
};
  • My code connect:
await connectTo(WALLET_CONNECTORS.AUTH, {
        authConnection: AUTH_CONNECTION.EMAIL_PASSWORDLESS,
        authConnectionId: 'w3a-email-btn',
        extraLoginOptions: {
          login_hint: email,
        },
      });
  • My code get privateKey:
import { useWeb3Auth as useWeb3AuthContext, useWeb3AuthUser } from '@web3auth/modal/react';
const { web3Auth, provider, status } = useWeb3AuthContext();
const privateKey = await web3Auth?.provider?.request({ method: METHOD_GET_PRIVATE_KEY[walletType] });

Unable to get privateKey from Solana Chain using “solanaPrivateKey” method.
I have not found the cause, please help me. Thank you very much.

Thank you for providing detailed information about your integration and the issue you’re facing. Here’s a summary for the support team and a few suggestions that might help you troubleshoot:


Issue Summary

  • SDK & Version:

  • Platform:
    ReactJS (Web Browser)

  • Chain:
    Solana (attempting to retrieve private key using “solanaPrivateKey” method)

  • Login Method:
    Email Passwordless (authConnectionId: ‘w3a-email-btn’)

  • Web3Auth Network:
    SAPPHIRE_DEVNET

  • Code Snippet for Private Key Retrieval:

    const privateKey = await web3Auth?.provider?.request({ method: METHOD_GET_PRIVATE_KEY[walletType] });
    
  • Observed Issue:
    Unable to retrieve the private key for Solana using the “solanaPrivateKey” method.

  • Console Screenshot:
    (Provided, but the image is not visible in this context—please ensure the support team can view it.)

  • Project Settings Screenshot:
    (Provided, but the image is not visible in this context.)


Additional Details for Support Team

  • Web3Auth Initialization and Login Code:
    Provided in the user’s message.
  • No indication of custom authentication (e.g., JWT, custom verifier) – using standard Email Passwordless.
  • No JWKS endpoint or idToken provided (not needed for standard social/email login).

Possible Causes & Suggestions

  1. Correct Method Name:
    For Solana, the correct method to retrieve the Ed25519 private key is usually "solanaPrivateKey" or "private_key", depending on the SDK version.
    Reference: Web3Auth Docs – Solana Integration (Web)

  2. Provider Availability:
    Double-check that web3Auth.provider is not null and is ready before making the request. Sometimes, the provider may not be initialized immediately after login.

  3. Method Mapping:
    Ensure that METHOD_GET_PRIVATE_KEY[walletType] resolves to "solanaPrivateKey" for Solana. You might want to try explicitly:

    const privateKey = await web3Auth?.provider?.request({ method: "solanaPrivateKey" });
    
  4. Network Support:
    Confirm that the selected network (SAPPHIRE_DEVNET) supports Solana private key retrieval. If not, try switching to a supported network.

  5. SDK Version Compatibility:
    There may be compatibility issues with the versions used. Check the Web3Auth Changelog for any breaking changes or updates related to Solana support.

  6. Console Errors:
    Since you provided a screenshot, please ensure the support team checks for any specific error messages in the browser console (e.g., “method not found”, “not supported”, etc.).


Next Steps

  • If you see a specific error message in the console, please copy and paste it here.
  • If possible, try updating all Web3Auth packages to their latest versions and test again.
  • Review the official Solana integration guide for Web (React) for any missed configuration steps.

If you have any additional error messages or logs, please share them to help the team diagnose further.

Thank you for your detailed report! The support team will review this information and assist you further.

Note: This response was generated by an AI bot and may require further verification. The Web3Auth support team has tracked this issue and will be responding as soon as possible.

Additionally, we would recommend you to join our biweekly Office Hours to get this resolved even faster. Web3Auth Developer Office Hours

I changed to use web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET
And used the correct method const privateKey = await web3Auth?.provider?.request({ method: “solanaPrivateKey” });

But still got the following error:

{
    "code": -32603,
    "message": "The method solanaPrivateKey does not exist/is not available",
    "data": {
        "code": -32601,
        "message": "The method solanaPrivateKey does not exist/is not available",
        "cause": null
    },
    "stack": "Stack trace is not available."
}

Hi what is the goal here, could you please try checking this post: Get private key from solana wallet provider and convert it to a Keypair

Hey @bap.it.project,
Can you please try using this route?

I succeeded when I tried changing to method: “private_key”
Thanks for everyone’s help!