> For the complete documentation index, see [llms.txt](/llms.txt).

# Connect to Solana quickstart

This quickstart gets you up and running with MetaMask Connect Solana in a JavaScript dapp.

## Prerequisites

- [Node.js](https://nodejs.org/) version 19 or later installed.
- A package manager installed, such as [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm), [Yarn](https://yarnpkg.com/), [pnpm](https://pnpm.io/installation), or [bun](https://bun.sh/).
- [MetaMask](https://metamask.io/) installed in your browser or on mobile.
- An [Infura API key](https://docs.infura.io/dashboard/get-started/create-api) from the [Infura dashboard](https://app.infura.io).

## Steps

### 1. Install MetaMask Connect Solana

Install the Solana Client in an existing JavaScript project:

**npm**

```bash
npm install @metamask/connect-solana

```

**Yarn**

```bash
yarn add @metamask/connect-solana

```

**pnpm**

```bash
pnpm add @metamask/connect-solana

```

**Bun**

```bash
bun add @metamask/connect-solana

```

### 2. Initialize MetaMask Connect Solana

Initialize the Solana client using [createSolanaClient](/metamask-connect/solana/reference/methods/#createsolanaclient). The following is an example of initializing the client in a JavaScript project:

```javascript
import { createSolanaClient, getInfuraRpcUrls } from '@metamask/connect-solana'

const solanaClient = await createSolanaClient({
  dapp: {
    name: 'Example JavaScript Solana dapp',
    url: window.location.href,
    iconUrl: 'https://mydapp.com/icon.png', // Optional
  },
  api: {
    supportedNetworks: getInfuraRpcUrls({
      infuraApiKey: 'YOUR_INFURA_API_KEY',
      networks: ['devnet'],
    }),
  },
})

```

info

[createSolanaClient](/metamask-connect/solana/reference/methods/#createsolanaclient) is async and uses a singleton multichain core under the hood. Calling it multiple times returns the same underlying session, so you can call it during initialization without worrying about duplicate connections.

This example configures MetaMask Connect Solana with the following options:

- `dapp` - Ensures trust by showing your dapp's `name`, `url`, and `iconUrl` during connection.
- `api.supportedNetworks` - A map of network names (`mainnet`, `devnet`, `testnet`) to RPC URLs for all networks supported by the dapp.

### 3. Connect and use the wallet

Get the [Wallet Standard](https://github.com/wallet-standard/wallet-standard) wallet instance and connect:

```javascript
const wallet = solanaClient.getWallet()

const { accounts } = await wallet.features['standard:connect'].connect()
console.log('Connected account:', accounts[0].address)

```

The client handles cross-platform connection (desktop and mobile), including deeplinking.

note

This example uses devnet. Devnet and testnet are supported only in the MetaMask browser extension. On mobile, only Solana mainnet is supported.

## Solana client methods at a glance

| Method                                                                       | Description                                                                                                |
| ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| [getWallet](/metamask-connect/solana/reference/methods/#getwallet)           | Returns a [Wallet Standard](https://github.com/wallet-standard/wallet-standard) compatible wallet instance |
| [registerWallet](/metamask-connect/solana/reference/methods/#registerwallet) | Registers MetaMask with the Wallet Standard registry (no-op if auto-registered)                            |
| [disconnect](/metamask-connect/solana/reference/methods/#disconnect)         | Disconnects Solana scopes without terminating the broader multichain session                               |

## Usage example

```javascript
const wallet = solanaClient.getWallet()

// 1. Connect and get accounts
try {
  const { accounts } = await wallet.features['standard:connect'].connect()
  console.log('Connected:', accounts[0].address)

  // 2. Sign a message
  const message = new TextEncoder().encode('Hello from my dapp')
  const [{ signature }] = await wallet.features['solana:signMessage'].signMessage({
    account: accounts[0],
    message,
  })
  console.log('Signature:', signature)
} catch (err) {
  if (err.code === 4001) {
    console.log('User rejected the request')
  } else if (err.code === -32002) {
    console.log('A request is already pending — check MetaMask')
  } else {
    console.error('Unexpected error:', err)
  }
}

// 3. Disconnect
await solanaClient.disconnect()

```

## Next steps

- [Use the Wallet Adapter](/metamask-connect/solana/guides/use-wallet-adapter/) to integrate MetaMask with Solana's standard wallet discovery in a React dapp.
- [Send a legacy transaction](/metamask-connect/solana/guides/send-transactions/legacy/) to transfer SOL or interact with programs.
- [Sign messages](/metamask-connect/solana/guides/sign-data/sign-message/) to verify wallet ownership or authorize offchain actions.
