> ## 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.

# 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(): BigInteger
```

#### Returns

* **BigInteger**: Current gas price in Wei

#### 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(transaction: EthereumTransaction, wallet: BaseWallet): String
```

#### Parameters

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

#### Returns

* **String**: Transaction hash

#### Example

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

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

### sendSponsoredTransaction

Send a gas-sponsored transaction on an EVM chain. The relayer pays the gas; see [EVM Gas Sponsorship](https://docs.dynamic.xyz/docs/kotlin/wallets/evm/gas-sponsorship.md).

```kotlin theme={"system"}
suspend fun sendSponsoredTransaction(calls: List<EvmSponsoredCall>, wallet: BaseWallet): String
```

#### Parameters

* **calls** (`List<EvmSponsoredCall>`): The calls to execute atomically, each with `target`, `data`, and `value`
* **wallet** (BaseWallet): The wallet to send from

#### Returns

* **String**: Transaction hash

#### Example

```kotlin theme={"system"}
val txHash = sdk.evm.sendSponsoredTransaction(
    calls = listOf(
        EvmSponsoredCall(target = recipientAddress, data = "0x", value = "1000000000000000")
    ),
    wallet = wallet
)
```

### isGasSponsorshipEnabled

Check whether EVM gas sponsorship is enabled for the current environment and wallet.

```kotlin theme={"system"}
suspend fun isGasSponsorshipEnabled(): Boolean
```

#### Returns

* **Boolean**: `true` when the environment can sponsor EVM transactions

### erc20Allowance

Read the ERC-20 allowance an owner granted a spender.

```kotlin theme={"system"}
suspend fun erc20Allowance(token: String, owner: String, spender: String, chainId: Int): BigInteger
```

#### Parameters

* **token** (String): The ERC-20 contract address
* **owner** (String): The wallet address that granted the allowance
* **spender** (String): The address allowed to spend
* **chainId** (Int): The chain to query

#### Returns

* **BigInteger**: The current allowance in raw token units

### signEthereumTransaction

Sign a transaction without sending it. This is an extension on `sdk.wallets`, so it requires an import.

```kotlin theme={"system"}
import com.dynamic.sdk.android.Chains.EVM.signEthereumTransaction

suspend fun signEthereumTransaction(walletId: String, transaction: EthereumTransaction): String
```

#### Parameters

* **walletId** (String): The ID of the wallet to sign with
* **transaction** (EthereumTransaction): Transaction to sign

#### Returns

* **String**: Signed transaction

#### Example

```kotlin theme={"system"}
viewModelScope.launch {
    try {
        val signedTx = sdk.wallets.signEthereumTransaction(wallet.id, 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`)

Building Solana transactions and fetching a blockhash use the `sol4k` library bundled via `solana-web3.aar`. Signing and sending go through `sdk.solana`.

### createConnection (sol4k)

Create a connection to a Solana network using `sol4k`.

```kotlin theme={"system"}
import com.solanaweb3.Connection
import com.solanaweb3.Cluster

val connection = Connection(Cluster.DEVNET)
```

#### Example

```kotlin theme={"system"}
val connection = Connection(Cluster.DEVNET)
val blockhash = connection.getLatestBlockhash()
```

### signMessage

Sign a message with a Solana wallet via the wallets module.

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

#### Parameters

* **wallet** (BaseWallet): The Solana wallet to sign with
* **message** (String): The message to sign

#### Returns

* **String**: The signature

#### Example

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

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

### signTransaction

Sign a Solana transaction (base64 encoded).

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

#### Parameters

* **base64Transaction** (String): Base64 encoded transaction
* **wallet** (BaseWallet): The Solana wallet to sign with

#### Returns

* **String**: Signed transaction

#### Example

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

### signAndSendTransaction

Sign and send a Solana transaction.

```kotlin theme={"system"}
suspend fun signAndSendTransaction(
    transaction: String,
    wallet: BaseWallet,
    transactionType: SolanaTransactionType = SolanaTransactionType.VERSIONED,
    sponsorshipMode: SolanaSponsorshipMode? = null
): String
```

#### Parameters

* **transaction** (String): Base64 encoded transaction
* **wallet** (BaseWallet): The Solana wallet to sign with
* **transactionType** (SolanaTransactionType, optional): Transaction encoding type, defaults to `VERSIONED`
* **sponsorshipMode** (SolanaSponsorshipMode?, optional): Overrides the project's SVM gas sponsorship for this transaction. `AUTO` follows the project setting, `OFF` always pays the fee from the wallet, `REQUIRED` fails when sponsorship is unavailable.

#### Returns

* **String**: Transaction signature

#### Example

```kotlin theme={"system"}
viewModelScope.launch {
    try {
        val signature = sdk.solana.signAndSendTransaction(base64Transaction, wallet)
        println("Transaction sent: $signature")
    } catch (e: Exception) {
        println("Transaction failed: ${e.message}")
    }
}
```

## Network Management (`sdk.networks`)

### Available Networks

Get lists of available EVM, Solana, SUI, and Bitcoin networks.

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

#### 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 from: String,                   // Sender address
    val to: String? = null,             // Recipient address
    val value: BigInteger? = null,      // Amount in Wei
    val data: String? = null,           // Contract data (optional)
    val gas: BigInteger? = null,        // Gas limit (optional)
    val gasPrice: BigInteger? = null,   // Gas price (optional)
    val maxFeePerGas: BigInteger? = null,      // Max fee per gas (optional)
    val maxPriorityFeePerGas: BigInteger? = null, // Priority fee (optional)
    val nonce: Int? = null              // Nonce (optional)
)
```

### WriteContractInput

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

### EstimatedFeesPerGas

```kotlin theme={"system"}
data class EstimatedFeesPerGas(
    val maxFeePerGas: BigInteger,
    val maxPriorityFeePerGas: BigInteger,
    val gasPrice: BigInteger
)
```

### GenericNetwork

```kotlin theme={"system"}
data class GenericNetwork(
    val name: String,
    val chainId: Any?,      // For EVM networks
    val networkId: Any?     // For Solana networks
    // Additional fields: rpcUrls, blockExplorerUrls, nativeCurrency, ...
)
```


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