> ## Documentation Index
> Fetch the complete documentation index at: https://solana.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> This page is part of the Solana developer documentation at https://solana.com/developers/docs. Append `.md` to any docs URL, or send `Accept: text/markdown`, to get the page as Markdown.
> Index of all pages: https://solana.com/llms.txt. Per-section indexes such as https://solana.com/developers/docs/payments/llms.txt are smaller; prefer them when working on one task.
> Coding agents: install the official Solana skill for current APIs and conventions with `npx skills add https://github.com/solana-foundation/solana-dev-skill` (also served at https://solana.com/SKILL.md).
> Code in the cookbook and task pages comes from tested example files. Prefer it over writing API calls from memory.

# Connecting to a Solana Environment

> Learn how to connect to a Solana environment.

To develop on Solana, you first need to connect to a Solana cluster.

| Cluster   | RPC Endpoint                     |
| --------- | -------------------------------- |
| mainnet   | `https://api.mainnet.solana.com` |
| devnet    | `https://api.devnet.solana.com`  |
| testnet   | `https://api.testnet.solana.com` |
| localhost | `http://localhost:8899`          |

## Connect using RPC URL

Connect to a specific RPC endpoint:

<CodeGroup>

```ts Kit
import { createSolanaRpc, createSolanaRpcSubscriptions } from "@solana/kit";

const rpc = createSolanaRpc("https://api.devnet.solana.com");
const rpcSubscriptions = createSolanaRpcSubscriptions(
  "wss://api.devnet.solana.com",
);
```

```ts title="Web3.js v3"
import { Connection } from "@solana/web3.js";

const connection = new Connection("https://api.devnet.solana.com", "confirmed");
```

```rust Rust
use solana_client::nonblocking::rpc_client::RpcClient;
use solana_commitment_config::CommitmentConfig;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let _client = RpcClient::new_with_commitment(
        String::from("https://api.devnet.solana.com"),
        CommitmentConfig::confirmed(),
    );
    Ok(())
}
```

```py Python
from solana.rpc.async_api import AsyncClient
from solana.rpc.commitment import Confirmed

client = AsyncClient("https://api.devnet.solana.com", commitment=Confirmed)
```

```go Go
package main

import "github.com/solana-foundation/solana-go/v2/rpc"

func main() {
	client := rpc.New("https://api.devnet.solana.com")
	_ = client
}
```

<Warning>
  **`@solana/web3.js` 1.x is no longer actively maintained**

  It receives critical fixes only. Use [Kit](/developers/docs/clients/official/javascript#solana-kit) for new code. To migrate existing code, follow the [Kit upgrade guide](https://www.solanakit.com/docs/upgrade-guide), or the [web3.js v3 migration guide](https://github.com/solana-foundation/solana-web3.js/blob/main/docs/web3js-v1-to-v3-migration.md) to keep the class-based API.

  To run this code, install 1.x with `npm install @solana/web3.js@1`. A plain `npm install @solana/web3.js` installs v3, which this code doesn't run on.
</Warning>

```ts title="Web3.js (legacy)"
import { Connection } from "@solana/web3.js";

const connection = new Connection("https://api.devnet.solana.com", "confirmed");
```

</CodeGroup>

## Connect using the network moniker

You can also connect to a public RPC endpoint by specifying its network name
(moniker):

<CodeGroup>

```ts title="Web3.js v3"
import { clusterApiUrl, Connection } from "@solana/web3.js";

const connection = new Connection(clusterApiUrl("mainnet-beta"), "confirmed");
```

```py Python
from solana.rpc.async_api import AsyncClient
from solana.rpc.commitment import Confirmed

# Pass the cluster's public endpoint directly.
client = AsyncClient("https://api.mainnet-beta.solana.com", commitment=Confirmed)
```

```go Go
package main

import "github.com/solana-foundation/solana-go/v2/rpc"

func main() {
	client := rpc.New(rpc.MainNetBeta_RPC)
	_ = client
}
```

<Warning>
  **`@solana/web3.js` 1.x is no longer actively maintained**

  It receives critical fixes only. Use [Kit](/developers/docs/clients/official/javascript#solana-kit) for new code. To migrate existing code, follow the [Kit upgrade guide](https://www.solanakit.com/docs/upgrade-guide), or the [web3.js v3 migration guide](https://github.com/solana-foundation/solana-web3.js/blob/main/docs/web3js-v1-to-v3-migration.md) to keep the class-based API.

  To run this code, install 1.x with `npm install @solana/web3.js@1`. A plain `npm install @solana/web3.js` installs v3, which this code doesn't run on.
</Warning>

```ts title="Web3.js (legacy)"
import { clusterApiUrl, Connection } from "@solana/web3.js";

const connection = new Connection(clusterApiUrl("mainnet-beta"), "confirmed");
```

</CodeGroup>
