Skip to content

About

No description, website, or topics provided.

Resources

Stars

3 stars

Watchers

0 watching

Forks

Repository files navigation

Alchemy Sdk Multiplatform

CircleCI codecov Kotlin badge-android badge-ios

Support Alchemy on Android and iOS devices thanks to kotlin multi-platform. This is a side project to learn stuff around web3 and releasing a library.

Roadmap

  • core api
  • nft api
  • ens support
  • transact api (missing wait for transaction that requires ws)
  • websocket api
  • wallet api

The API is subject to heavy changes in the upcoming releases

Getting started

Add the github repository to your gradle config:

repositories {
    maven {
        name = "GitHubPackages"
        url = uri("https://maven.pkg.github.com/tguerin/alchemy-sdk-kotlin")
        credentials {
            username = "username"
            password = "personal access token with read permission"
        }
    }
}

then just add the dependency to the required module:

val commonMain by getting { 
    dependencies {
        implementation("com.github.tguerin:alchemy-core:0.10.0")
    }
}

Using Alchemy sdk

This Alchemy sdk relies on coroutines, the api is quite straightforward:

Core

val alchemy = Alchemy.with(AlchemySettings(network = Network.ETH_MAINNET))

coroutineScope.launch {
    val result = alchemy.core.getBalance(Address.from("0x1188aa75c38e1790be3768508743fbe7b50b2153"))
    val balance = result.getOrElse { 
        // handle failure
    }
}

Websocket

The websocket api returns a Flow:

val alchemy = Alchemy.with(AlchemySettings(network = Network.ETH_MAINNET))

coroutineScope.launch {
    alchemy.ws.on(WebsocketMethod.Block).collect { event ->
        // handle data
    }
    alchemy.ws.status.collect { connectionStatus ->
        // You can display if you are connected or not to the websocket
    }
}

The websocket will automatically close if no subscriber is registered. Also it will transparently resubscribe to previous topics when websocket is reconnected.

Have a look at the e2e tests for samples.

About

No description, website, or topics provided.

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages