Solana: Error: expected environment variable `ANCHOR_WALLET` is not set

Error: Anchor Wallet is not configured on Solana node

The error message indicates that the ANCHOR_WALLET environment variable is not set, which is causing an issue with setting up a connection to a Solana cluster. This can be frustrating, especially when working with Anchor projects.

Error Description

When you run your application or script, it attempts to connect to a Solana cluster using the Connection class provided by the Anchor SDK. However, without the necessary environment variables set, the connection attempt fails.

Solution: Setting Environment Variables

To resolve this issue, you need to ensure that the ANCHOR_WALLET environment variable is set on your Solana node. Here’s how to do that:

  • Check Node Version – Make sure that your Solana node version is supported by Anchor. You can check the version with the following command:

solana-cli -v

  • Set an environment variable on your node

    :

You can set an environment variable directly on your operating system. Here’s how to do it for Linux and macOS:

Linux:

Solana: Error: expected environment variable `ANCHOR_WALLET` is not set

  • Create a new file named .env with the following content:

ANCHOR_WALLET="your-anchor-wallet-password"

  • Set the ANCHOR_WALLET environment variable in your shell configuration file (e.g. ~/.bashrc or ~/.zshrc). Add the following line to set the variable:

export ANCHOR_WALLET="your-anchor-wallet-password"

  • Restart your terminal or run source ~/.bashrc to apply the changes.

macOS:

  • Create a new file named .env with the following contents:

ANCHOR_WALLET="your-anchor-wallet-password"

  • Set the ANCHOR_WALLET environment variable in your shell configuration file (e.g., ~/.bash_profile or ~/.zshrc). Add the following line to set the variable:

export ANCHOR_WALLET="your-anchor-wallet-password"

Verify Environment Variable

After setting the environment variable, verify that it is present by running the following command:

echo $ANCHOR_WALLET

If you see the value for your ANCHOR_WALLET environment variable, it means everything is working as expected.

Next Steps:

Once you have set the environment variable, you should be able to connect to a Solana cluster using the Anchor SDK. Be sure to check out the official Anchor documentation for any additional settings or requirements specific to your use case.

If you are still having issues, feel free to provide more details about your setup and error messages for further assistance.

solana holders