{"id":13572955,"url":"https://github.com/polywrap/kotlin-client","last_synced_at":"2026-04-15T04:30:20.236Z","repository":{"id":150837424,"uuid":"617048805","full_name":"polywrap/kotlin-client","owner":"polywrap","description":null,"archived":false,"fork":false,"pushed_at":"2023-08-31T14:48:42.000Z","size":374148,"stargazers_count":2,"open_issues_count":8,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-11-05T07:35:29.552Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/polywrap.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-03-21T15:46:17.000Z","updated_at":"2023-11-20T06:20:31.000Z","dependencies_parsed_at":"2024-03-17T04:51:20.998Z","dependency_job_id":null,"html_url":"https://github.com/polywrap/kotlin-client","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polywrap%2Fkotlin-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polywrap%2Fkotlin-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polywrap%2Fkotlin-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polywrap%2Fkotlin-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/polywrap","download_url":"https://codeload.github.com/polywrap/kotlin-client/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240005381,"owners_count":19732742,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T15:00:25.233Z","updated_at":"2026-04-15T04:30:19.776Z","avatar_url":"https://github.com/polywrap.png","language":"Kotlin","readme":"![Public Release Announcement](https://user-images.githubusercontent.com/5522128/177473887-2689cf25-7937-4620-8ca5-17620729a65d.png)\n\n[**Polywrap**](https://polywrap.io/) is a developer tool that enables easy integration of Web3 protocols into any application. It makes it possible for applications on any platform, written in any language, to read and write data to Web3 protocols.\n\nThis repository hosts a Kotlin implementation of the Polywrap Client for Android/JVM.\n\nThe readiness of the Kotlin client is tracked at https://github.com/polywrap/client-readiness\n\n# Installation\n\nKotlin\n```kotlin\nplugins {\n    kotlin(\"plugin.serialization\") version \"1.x.x\" // Required for serialization\n}\n\ndependencies {\n    implementation(\"io.polywrap:polywrap-client:0.10.4\")\n    implementation(\"org.jetbrains.kotlinx:kotlinx-serialization-core:1.x.x\") // Required for serialization\n}\n```\n\nGroovy\n```groovy\nplugins {\n    id 'org.jetbrains.kotlin.plugin.serialization' version '1.x.x' // Required for serialization\n}\n\ndependencies {\n    implementation \"io.polywrap:polywrap-client:0.10.4\"\n    implementation \"org.jetbrains.kotlinx:kotlinx-serialization-core:1.x.x\" // Required for serialization\n}\n```\n\n# Quick Start\n\nThe following examples can be found in [SanityClientTest](https://github.com/polywrap/kotlin-client/blob/main/src/commonTest/kotlin/client/SanityClientTest.kt). Many more examples are available in the client section of the [tests](https://github.com/polywrap/kotlin-client/tree/main/src/commonTest/kotlin/client) and the Kotlin client's section of the [client readiness](https://github.com/polywrap/client-readiness/tree/main/clients/kotlin/src/main/kotlin/features) test harness.\n\n```kotlin\nimport io.polywrap.configBuilder.ConfigBuilder\nimport io.polywrap.configBuilder.polywrapClient\nimport io.polywrap.core.InvokeResult\nimport io.polywrap.core.resolution.Uri\nimport kotlinx.serialization.Serializable\n\nprivate val sha3Uri = Uri(\"ipfs/QmThRxFfr7Hj9Mq6WmcGXjkRrgqMG3oD93SLX27tinQWy5\")\n\n@Test\nfun invokeWithMapStringAnyArgs() {\n    // instantiate the client with default configuration using the polywrapClient builder DSL\n    val client = polywrapClient {\n        addDefaults()\n    }\n    // invoke the sha3 wrap with a Map\u003cString, Any\u003e of arguments\n    val result = client.invoke\u003cString\u003e(\n        uri = sha3Uri,\n        method = \"keccak_256\",\n        args = mapOf(\"message\" to \"Hello World!\")\n    )\n    assertNull(result.exceptionOrNull())\n    val hash = result.getOrThrow()\n    // to prevent a memory leak, close the client when you're done with it\n    // this typically happens at the end of your application's lifecycle\n    client.close()\n}\n\n@Test\nfun invokeWithReifiedTypes() {\n    @Serializable\n    data class Keccak256Args(val message: String)\n\n    // instantiate the client with default configuration using the builder pattern\n    val client = ConfigBuilder().addDefaults().build()\n    \n    // invoke the sha3 wrap with a serializable type\n    val result: InvokeResult\u003cString\u003e = client.invoke(\n        uri = sha3Uri,\n        method = \"keccak_256\",\n        args = Keccak256Args(\"Hello World!\")\n    )\n    assertNull(result.exceptionOrNull())\n    val hash = result.getOrThrow()\n}\n```\n\n# Examples \u0026 Documentation\n\nReference documentation is hosted at https://kotlin.client.polywrap.io/\n\n| Example     | Platform | Description                                                        | Location                                                                                                                                             |\n|-------------|----------|--------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------|\n| IPFS        | Android  | Add a file to IPFS and then retrieve it                            | [Link](https://github.com/polywrap/ipfs/tree/main/demos/kotlin)                                                                                      |\n| Ethereum    | JVM      | Sign typed data with the Ethers wrap                               | [Link](https://github.com/polywrap/ethereum-wallet/tree/main/implementations/kt/src/commonTest/kotlin/io/polywrap/plugins/ethereum/EthersExample.kt) |\n| ENS         | JVM      | Get the content hash of an ENS address                             | [examples/ens](./examples/ens)                                                                                                                       |\n| File System | JVM      | Write a file to the file system, read its contents, then remove it | [examples/fileSystem](./examples/fileSystem)                                                                                                         |\n| HTTP        | JVM      | Make an HTTP request                                               | [examples/http](./examples/http)                                                                                                                     |\n| Hello World | JVM      | Print a message to the console                                     | [Link](https://github.com/polywrap/logging/blob/main/logger/implementations/kt/src/test/kotlin/io/polywrap/plugins/logger/HelloWorld.kt)             |\n\n# Plugins\n\nThe Kotlin client supports plugins that can be used to extend its functionality. \n\nSome plugins are written in Rust and packaged with the Polywrap Client.\n- System Bundle: File-system and HTTP plugins\n- Web3 Bundle: Ethereum wallet plugin\n\n*The Rust Ethereum Wallet plugin is not configurable from Kotlin. For custom configuration, use the Kotlin Ethereum Wallet plugin instead.*\n\nThese plugins can be loaded with the `addDefaults` method of the `ConfigBuilder`, or added using the `addBundle` method.\n\n```kotlin\nval client = polywrapClient { addDefaults() }\n\nval client = polywrapClient {\n    addBundle(NativeBundle.System)\n    addBundle(NativeBundle.Web3)\n}\n```\n\nThe Rust plugins are located in the [Rust client repo](https://github.com/polywrap/rust-client/tree/main/packages/plugins).\n\nOther plugins are written in Kotlin. The available Kotlin plugins include:\n\n| Plugin          | Description                                                                    | Maven publication                          | Location                                                                         |\n|-----------------|--------------------------------------------------------------------------------|--------------------------------------------|----------------------------------------------------------------------------------|\n| Ethereum Wallet | Support the Ethers wrap with an configurable Ethereum signer or RPC connection | io.polywrap.plugins:ethereum-wallet:0.10.4 | [Link](https://github.com/polywrap/ethereum-wallet/tree/main/implementations/kt) |\n| Logger          | Enable logging in Wasm wraps with SL4J                                         | io.polywrap.plugins:logger:0.10.4          | [Link](https://github.com/polywrap/logging/tree/main/logger/implementations/kt)  |\n| File System     | Interact with the host file system                                             | io.polywrap.plugins:file-system:0.10.4     | [Link](https://github.com/polywrap/file-system/tree/main/implementations/kt)     |\n| HTTP            | Send HTTP requests                                                             | io.polywrap.plugins:http:0.10.4            | [Link](https://github.com/polywrap/http/tree/main/implementations/kt)            |\n\n# Using GenericMap\n\nThe `GenericMap` type is implemented as an extension type for MessagePack serialization.\n\n```kotlin\n@Serializable(with = GenericMapExtensionSerializer::class)\ndata class GenericMap\u003cK, V\u003e(val map: Map\u003cK, V\u003e)\n```\n\nIn practice, this means you must wrap a `Map\u003cK, V\u003e` in a `GenericMap\u003cK, V\u003e` before passing it to the client.\n```kotlin\nval myMap: Map\u003cString, Int\u003e = mapOf(\"Hello\" to 1, \"Heyo\" to 50)\nval genericMap: GenericMap\u003cString, Int\u003e = GenericMap(myMap)\nval alsoGenericMap: GenericMap\u003cString, Int\u003e = myMap.toGenericMap()\nval myMapReference: Map\u003cString, Int\u003e = genercMap.map\n```\n\nIt also means the client will return a `GenericMap\u003cK, V\u003e`, not a `Map\u003cK,V\u003e`.\n```kotlin\n@Serializable\ndata class ArgsReturnMap(val map: GenericMap\u003cString, Int\u003e)\n\n@Test\nfun testReturnMap() = runTest {\n    val genericMap = mapOf(\"Hello\" to 1, \"Heyo\" to 50).toGenericMap()\n    \n    val result: InvokeResult\u003cGenericMap\u003cString, Int\u003e\u003e = client.invoke(\n        uri = uri,\n        method = \"returnMap\",\n        args = ArgsReturnMap(genericMap)\n    )\n    \n    if (result.isFailure) throw result.exceptionOrNull()!!\n    assertEquals(genericMap, result.getOrThrow())\n}\n```\n\nA contextual serializer is provided for `GenericMap\u003cK, V\u003e` to help the `kotlinx.serialization` framework find the `GenericMapExtensionSerializer` serializer when the `@Contextual` annotation is used.\n```kotlin\n@Serializable\ndata class ArgsReturnMap(\n    @Contextual\n    val map: GenericMap\u003cString, Int\u003e\n)\n```\n\nIt is often preferable to annotate a typealias to help the `kotlinx.serialization` framework find the serializer.\n```kotlin\ntypealias GenericMap\u003cK, V\u003e = @Serializable(with = GenericMapExtensionSerializer::class) io.polywrap.core.msgpack.GenericMap\u003cK,V\u003e\n```\n\n# Memory Management\nThe Kotlin client relies on a native library containing the [Rust version of the Polywrap Client](https://github.com/polywrap/rust-client). Some Kotlin objects contain pointers to natively allocated memory. These objects implement the `Autoclosable` interface and should be closed when the memory resources are no longer needed. Once closed, these objects cannot be used again.\n\nThe client `ConfigBuilder` takes ownership of its configuration and closes those resources for you. In most cases, the client is the only object that needs to be manually closed.\n\n```kotlin\nval client = polywrapClient { \n    addDefaults() \n}\n// do stuff with the client\n// ...\n// close the client to avoid a memory leak\nclient.close()\n```\n\n```kotlin\nval client = ConfigBuilder().addDefaults().build()\n// the autocloseable interface provides the `use` extension function, \n// which closes the resource when the block completes (even if an exception is thrown)\nclient.use {\n    // do stuff with the client\n}\n```\n\n# Development\n\n### Build\n\nRun the following to compile the project:\n\n```\n./gradlew assemble\n```\n\n### Test\n\nRun the following to run all checks:\n\n```\n./gradlew jvmTest\n```\n\n### Lint\n\nTo lint the project, run the following:\n\n```\n./gradlew ktlintCheck\n```\n\nTo auto-fix lint errors:\n\n```\n./gradlew ktlintFormat\n```\n\n# Resources\n- [Website](https://polywrap.io/)\n- [Documentation](https://docs.polywrap.io/)\n- [Forum](https://forum.polywrap.io/)","funding_links":[],"categories":["Clients"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolywrap%2Fkotlin-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpolywrap%2Fkotlin-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolywrap%2Fkotlin-client/lists"}