getChainId

abstract suspend fun getChainId(): Result<Long, AptosSdkError>

Retrieves the chain ID of the connected network.

Usage

val aptos = Aptos(AptosConfig(AptosSettings(network = Network.LOCAL)))
val resolution = aptos.getChainId()

when (resolution) {
is Result.Ok -> {
val chainId = resolution.value
// Expected for localnet: 4
println("Network Chain ID: $chainId")
}
is Result.Err -> {
println("Error retrieving chain ID: ${resolution.error.message}")
}
}

Return

A Result which is either Result.Ok containing the chain ID as a Long, or Result.Err containing an AptosSdkError.