It is difficult to troubleshoot your error with seeing any of your code, but it looks like you are incorrectly setting an RPC url (or maybe even not setting one at all) when you initiate your Connection
to your Solana RPC provider.
Using the @solana/web3.js
package, you can create a new connection to any RPC via its url. Including using one of the public RPC listed in the Solana Docs.
import { Connection, clusterApiUrl } from "@solana/web3.js"
// connect to 'devnet' via the public endpoint
const connection = new Connection(clusterApiUrl("devnet"));
// connect to 'mainnet' via the public endpoint
const connection = new Connection(clusterApiUrl("mainnet-beta"));
// connect to any other RPC provider's url (this url will be provided by them)
const connection = new Connection("https://yourprovider.tld")
Note: clusterApiUrl
is a helper function inside the web3.js package for more easily connecting to the public RPC endpoints, but should be not used for production apps since you will hit rate limits.
Now that you should have a valid connection
, you can tell Anchor to use it when your create your provider
:
const provider = new anchor.AnchorProvider(connection, wallet, {
commitment: "processed",
});
// note: the `wallet` variable is not included in this code snippet
Not specifically part of your initial question, but worth noting:
I also see you are using the deprecated @project-serum/anchor
Anchor package. This package is not maintained and should NOT be used anymore.
You should instead install the official Anchor package @coral-xyz/anchor
from the creators and maintainers of Anchor (their company name is Coral):
yarn remove @project-serum/anchor
yarn add @coral-xyz/anchor
FYI: You might also need to delete your node modules directory and reinstall all packages if you run into issues with this too.