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

# Blockchain Integration

## EVM Operations (`sdk.evm`)

### createPublicClient

Create a public client for interacting with an EVM chain.

```kotlin theme={"system"}
fun createPublicClient(chainId: Int): EvmPublicClient
```

#### Parameters

* **chainId** (Int) - The chain ID (e.g., 1 for Ethereum mainnet, 137 for Polygon)

#### Returns

* **EvmPublicClient** - Public client for the chain

#### Example

```kotlin theme={"system"}
val sdk = DynamicSDK.getInstance()
val client = sdk.evm.createPublicClient(chainId = 1) // Ethereum mainnet
```

### getGasPrice

Get the current gas price for a chain.

```kotlin theme={"system"}
suspend fun getGasPrice(): GasPrice
```

#### Returns

* **GasPrice** - Current gas price information

#### Example

```kotlin theme={"system"}
val client = sdk.evm.createPublicClient(chainId = 1)

viewModelScope.launch {
    try {
        val gasPrice = client.getGasPrice()
        println("Gas price: $gasPrice")
    } catch (e: Exception) {
        println("Failed to get gas price: ${e.message}")
    }
}
```

### sendTransaction

Send a transaction on an EVM chain.

```kotlin theme={"system"}
suspend fun sendTransaction(wallet: BaseWallet, transaction: EthereumTransaction): String
```

#### Parameters

* **wallet** (BaseWallet) - The wallet to send from
* **transaction** (EthereumTransaction) - Transaction details

#### Returns

* **String** - Transaction hash

#### Example

```kotlin theme={"system"}
val sdk = DynamicSDK.getInstance()

viewModelScope.launch {
    try {
        val transaction = EthereumTransaction(
            to = recipientAddress,
            value = "1000000000000000", // 0.001 ETH in Wei
            gasLimit = 21000
        )
        val txHash = sdk.evm.sendTransaction(wallet, transaction)
        println("Transaction sent: $txHash")
    } catch (e: Exception) {
        println("Transaction failed: ${e.message}")
    }
}
```

### signTransaction

Sign a transaction without sending it.

```kotlin theme={"system"}
suspend fun signTransaction(wallet: BaseWallet, transaction: EthereumTransaction): String
```

#### Parameters

* **wallet** (BaseWallet) - The wallet to sign with
* **transaction** (EthereumTransaction) - Transaction to sign

#### Returns

* **String** - Signed transaction

#### Example

```kotlin theme={"system"}
viewModelScope.launch {
    try {
        val signedTx = sdk.evm.signTransaction(wallet, transaction)
        println("Signed transaction: $signedTx")
    } catch (e: Exception) {
        println("Failed to sign: ${e.message}")
    }
}
```

### writeContract

Write to a smart contract (call a contract function).

```kotlin theme={"system"}
suspend fun writeContract(wallet: BaseWallet, input: WriteContractInput): String
```

#### Parameters

* **wallet** (BaseWallet) - The wallet to call from
* **input** (WriteContractInput) - Contract call parameters

#### Returns

* **String** - Transaction hash

#### Example

```kotlin theme={"system"}
val sdk = DynamicSDK.getInstance()

viewModelScope.launch {
    try {
        // Parse ERC20 ABI
        val abiList = parseAbiJson(Erc20.abi)

        // Calculate amount with decimals
        val decimals = 18
        val amount = BigDecimal("100")
        val multiplier = BigDecimal.TEN.pow(decimals)
        val rawAmount = amount.multiply(multiplier).toBigInteger()

        val input = WriteContractInput(
            address = tokenContractAddress,
            abi = abiList,
            functionName = "transfer",
            args = listOf(recipientAddress, rawAmount.toString())
        )

        val txHash = sdk.evm.writeContract(wallet, input)
        println("Contract write successful: $txHash")
    } catch (e: Exception) {
        println("Contract write failed: ${e.message}")
    }
}
```

## Solana Operations (`sdk.solana`)

### createConnection

Create a connection to a Solana network.

```kotlin theme={"system"}
fun createConnection(): SolanaConnection
```

#### Returns

* **SolanaConnection** - Connection to the Solana network

#### Example

```kotlin theme={"system"}
val sdk = DynamicSDK.getInstance()
val connection = sdk.solana.createConnection()
```

### getLatestBlockhash

Get the latest blockhash for transaction creation.

```kotlin theme={"system"}
suspend fun getLatestBlockhash(): BlockhashResult
```

#### Returns

* **BlockhashResult** - Contains the blockhash and last valid block height

#### Example

```kotlin theme={"system"}
val connection = sdk.solana.createConnection()

viewModelScope.launch {
    try {
        val blockhashResult = connection.getLatestBlockhash()
        val blockhash = blockhashResult.blockhash
        println("Latest blockhash: $blockhash")
    } catch (e: Exception) {
        println("Failed to get blockhash: ${e.message}")
    }
}
```

### createSigner

Create a signer for signing Solana transactions.

```kotlin theme={"system"}
fun createSigner(wallet: BaseWallet): SolanaSigner
```

#### Parameters

* **wallet** (BaseWallet) - The Solana wallet

#### Returns

* **SolanaSigner** - Signer for the wallet

#### Example

```kotlin theme={"system"}
val sdk = DynamicSDK.getInstance()
val signer = sdk.solana.createSigner(wallet)
```

### signMessage

Sign a message with a Solana wallet.

```kotlin theme={"system"}
suspend fun signMessage(message: String): String
```

#### Parameters

* **message** (String) - The message to sign

#### Returns

* **String** - The signature

#### Example

```kotlin theme={"system"}
val signer = sdk.solana.createSigner(wallet)

viewModelScope.launch {
    try {
        val signature = signer.signMessage("Hello from Dynamic SDK!")
        println("Signature: $signature")
    } catch (e: Exception) {
        println("Failed to sign message: ${e.message}")
    }
}
```

### signEncodedTransaction

Sign a Solana transaction (base64 encoded).

```kotlin theme={"system"}
suspend fun signEncodedTransaction(base64Transaction: String): String
```

#### Parameters

* **base64Transaction** (String) - Base64 encoded transaction

#### Returns

* **String** - Signed transaction (base64 encoded)

#### Example

```kotlin theme={"system"}
val signer = sdk.solana.createSigner(wallet)

viewModelScope.launch {
    try {
        val signedTx = signer.signEncodedTransaction(base64Transaction)
        println("Signed transaction: $signedTx")
    } catch (e: Exception) {
        println("Failed to sign transaction: ${e.message}")
    }
}
```

### signAndSendEncodedTransaction

Sign and send a Solana transaction.

```kotlin theme={"system"}
suspend fun signAndSendEncodedTransaction(base64Transaction: String): String
```

#### Parameters

* **base64Transaction** (String) - Base64 encoded transaction

#### Returns

* **String** - Transaction signature

#### Example

```kotlin theme={"system"}
val signer = sdk.solana.createSigner(wallet)

viewModelScope.launch {
    try {
        val signature = signer.signAndSendEncodedTransaction(base64Transaction)
        println("Transaction sent: $signature")
    } catch (e: Exception) {
        println("Transaction failed: ${e.message}")
    }
}
```

## Network Management (`sdk.networks`)

### Available Networks

Get lists of available EVM and Solana networks.

```kotlin theme={"system"}
val evmNetworks: List<GenericNetwork> = sdk.networks.evm
val solanaNetworks: List<GenericNetwork> = sdk.networks.solana
```

#### Example

```kotlin theme={"system"}
val sdk = DynamicSDK.getInstance()

// Get all EVM networks
val evmNetworks = sdk.networks.evm
evmNetworks.forEach { network ->
    println("EVM Network: ${network.name}, Chain ID: ${network.chainId}")
}

// Get all Solana networks
val solanaNetworks = sdk.networks.solana
solanaNetworks.forEach { network ->
    println("Solana Network: ${network.name}, Network ID: ${network.networkId}")
}

// Find a specific network
val polygon = evmNetworks.first { it.chainId == 137 }
println("Found Polygon: ${polygon.name}")
```

## Data Types

### EthereumTransaction

```kotlin theme={"system"}
data class EthereumTransaction(
    val to: String,                     // Recipient address
    val value: String,                  // Amount in Wei (as String)
    val gasLimit: Int,                  // Gas limit
    val maxFeePerGas: Int? = null,      // Max fee per gas (optional)
    val maxPriorityFeePerGas: Int? = null, // Priority fee (optional)
    val data: String? = null            // Contract data (optional)
)
```

### WriteContractInput

```kotlin theme={"system"}
data class WriteContractInput(
    val address: String,                // Contract address
    val functionName: String,           // Function to call
    val args: List<Any>,                // Function arguments
    val abi: List<Map<String, Any>>     // Contract ABI
)
```

### GasPrice

```kotlin theme={"system"}
data class GasPrice(
    val maxFeePerGas: Int,
    val maxPriorityFeePerGas: Int
)
```

### GenericNetwork

```kotlin theme={"system"}
data class GenericNetwork(
    val name: String,
    val chainId: Int?,      // For EVM networks
    val networkId: String?  // For Solana networks
)
```

### BlockhashResult

```kotlin theme={"system"}
data class BlockhashResult(
    val blockhash: String,
    val lastValidBlockHeight: Long
)
```
