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

# Solana Connection

> Learn how to create and manage Solana connections with the Dynamic Swift SDK.

## Overview

The Solana connection allows you to interact with the Solana blockchain, query data, and prepare transactions.

## Prerequisites

* Dynamic SDK initialized (see [Quickstart](https://docs.dynamic.xyz/docs/swift/quickstart.md))
* User authenticated (see [Authentication](https://docs.dynamic.xyz/docs/swift/authentication.md))
* Solana wallets enabled in your Dynamic Console

## Create Connection

```swift theme={"system"}
import DynamicSDKSwift

let sdk = DynamicSDK.instance()

func createConnection() throws {
    let connection = try sdk.solana.createConnection()
    print("Solana connection created")
}
```

## Get Latest Blockhash

Required for building transactions:

```swift theme={"system"}
import DynamicSDKSwift

let sdk = DynamicSDK.instance()

func getBlockhash() async throws -> String {
    let connection = try sdk.solana.createConnection()
    let result = try await connection.getLatestBlockhash()
    print("Latest blockhash: \(result.blockhash)")
    return result.blockhash
}
```

## Query Account Balance

```swift theme={"system"}
import DynamicSDKSwift
import SolanaWeb3

let sdk = DynamicSDK.instance()

func getBalance(address: String) async throws -> UInt64 {
    let connection = try sdk.solana.createConnection()

    guard let pubkey = try? PublicKey(string: address) else {
        throw SolanaError.invalidAddress
    }

    let balance = try await connection.getBalance(publicKey: pubkey)
    return balance
}

enum SolanaError: LocalizedError {
    case invalidAddress

    var errorDescription: String? {
        "Invalid Solana address"
    }
}
```

## Get Solana Wallets

```swift theme={"system"}
import DynamicSDKSwift

let sdk = DynamicSDK.instance()

let solanaWallets = sdk.wallets.userWallets.filter {
    $0.chain.uppercased() == "SOL"
}

for wallet in solanaWallets {
    print("Address: \(wallet.address)")
}
```

## Solana Networks

Access configured Solana networks:

```swift theme={"system"}
let sdk = DynamicSDK.instance()

let solanaNetworks = sdk.networks.solana

for network in solanaNetworks {
    print("Network: \(network.name)")
}
```

## Connection Methods

| Method | Description |
| - | - |
| `createConnection()` | Create a Solana connection instance |
| `getLatestBlockhash()` | Get the latest blockhash for transactions |
| `getBalance(publicKey:)` | Get account balance in lamports |
| `getAccountInfo(publicKey:)` | Get detailed account information |

## Dependencies

To build Solana transactions, add the SolanaWeb3 package:

```swift theme={"system"}
// Package.swift
dependencies: [
    .package(url: "https://github.com/solana-mobile/SolanaSwift", from: "1.0.0")
]
```

## Next Steps

* [Send Solana Transactions](https://docs.dynamic.xyz/docs/swift/wallets/solana/send-transactions.md) - Transfer SOL
* [Sign Solana Messages](https://docs.dynamic.xyz/docs/swift/wallets/solana/message-signing.md) - Sign messages
* [Token Balances](https://docs.dynamic.xyz/docs/swift/wallets/general/token-balances.md) - Get SOL balance


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.