{"id":13524511,"url":"https://github.com/seniorjoinu/candid-kt","last_synced_at":"2026-03-14T20:39:28.505Z","repository":{"id":45097441,"uuid":"266164614","full_name":"seniorjoinu/candid-kt","owner":"seniorjoinu","description":"Lets you write Kotlin apps which interact with the Internet Computer","archived":false,"fork":false,"pushed_at":"2022-01-09T00:56:49.000Z","size":402,"stargazers_count":17,"open_issues_count":12,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-14T17:06:40.872Z","etag":null,"topics":["android","candid","dfinity","ic","kotlin"],"latest_commit_sha":null,"homepage":"","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/seniorjoinu.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":null,"security":null,"support":null}},"created_at":"2020-05-22T17:04:31.000Z","updated_at":"2024-01-21T04:29:19.000Z","dependencies_parsed_at":"2022-09-16T14:41:41.631Z","dependency_job_id":null,"html_url":"https://github.com/seniorjoinu/candid-kt","commit_stats":null,"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seniorjoinu%2Fcandid-kt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seniorjoinu%2Fcandid-kt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seniorjoinu%2Fcandid-kt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seniorjoinu%2Fcandid-kt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/seniorjoinu","download_url":"https://codeload.github.com/seniorjoinu/candid-kt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248923766,"owners_count":21183953,"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":["android","candid","dfinity","ic","kotlin"],"created_at":"2024-08-01T06:01:10.790Z","updated_at":"2026-03-14T20:39:23.483Z","avatar_url":"https://github.com/seniorjoinu.png","language":"Kotlin","funding_links":[],"categories":["Candid","CDK\u0026Agent"],"sub_categories":["Candid implementations"],"readme":"\u003cimg src=\"https://github.com/seniorjoinu/candid-kt/blob/master/logo.png?raw=true\" align=\"left\" width=\"100%\" \u003e\n\n[![](https://jitci.com/gh/seniorjoinu/candid-kt/svg?style=flat-square)](https://jitci.com/gh/seniorjoinu/candid-kt)\n[![Release](https://jitpack.io/v/seniorjoinu/candid-kt.svg?style=flat-square)](https://jitpack.io/#seniorjoinu/candid-kt)\n\u003cimg src=\"https://img.shields.io/badge/dfx-0.6.7-blue?style=flat-square\"/\u003e\n\u003cimg src=\"https://img.shields.io/badge/kotlin-1.3-blue?style=flat-square\"/\u003e\n\u003cimg src=\"https://img.shields.io/badge/android-26+-blue?style=flat-square\"/\u003e\n\n### Candid-kt\nGenerates client code for your canisters\n\n### Usage\n\nUse [the gradle plugin](https://github.com/seniorjoinu/candid-kt-gradle-plugin) to generate Kotlin code out of candid code.\n\nFor example, this candid code\n```\ntype Phone = nat;\ntype Name = text;\ntype Entry = \n record {\n   description: text;\n   name: Name;\n   phone: Phone;\n };\nservice : {\n  insert: (Name, text, Phone) -\u003e ();\n  lookup: (Name) -\u003e (opt Entry) query;\n}\n```\nwould generate this Kotlin code\n```kotlin\ntypealias Phone = BigInteger\n\nval PhoneValueSer: ValueSer\u003cBigInteger\u003e = NatValueSer\n\ntypealias Name = String\n\nval NameValueSer: ValueSer\u003cString\u003e = TextValueSer\n\ndata class Entry(\n    val name: Name,\n    val description: String,\n    val phone: Phone\n)\n\nobject EntryValueSer : ValueSer\u003cEntry\u003e {\n    val nameValueSer: ValueSer\u003cName\u003e = NameValueSer\n\n    val descriptionValueSer: ValueSer\u003cString\u003e = TextValueSer\n\n    val phoneValueSer: ValueSer\u003cPhone\u003e = PhoneValueSer\n\n    override fun calcSizeBytes(value: Entry): Int = this.nameValueSer.calcSizeBytes(value.name) +\n            this.descriptionValueSer.calcSizeBytes(value.description) +\n            this.phoneValueSer.calcSizeBytes(value.phone)\n\n    override fun ser(buf: ByteBuffer, value: Entry) {\n        this.nameValueSer.ser(buf, value.name)\n        this.descriptionValueSer.ser(buf, value.description)\n        this.phoneValueSer.ser(buf, value.phone)\n    }\n\n    override fun deser(buf: ByteBuffer): Entry = Entry(this.nameValueSer.deser(buf),\n        this.descriptionValueSer.deser(buf), this.phoneValueSer.deser(buf))\n\n    override fun poetize(): String = Code.of(\"%T\", EntryValueSer::class)\n}\n\ntypealias PhonebookServiceValueSer = ServiceValueSer\n\ntypealias AnonFunc0ValueSer = FuncValueSer\n\nclass AnonFunc0(\n    funcName: String?,\n    service: SimpleIDLService?\n) : SimpleIDLFunc(funcName, service) {\n    suspend operator fun invoke(\n        arg0: Name,\n        arg1: String,\n        arg2: Phone\n    ) {\n        val arg0ValueSer = NameValueSer\n        val arg1ValueSer = senior.joinu.candid.serialize.TextValueSer\n        val arg2ValueSer = PhoneValueSer\n        val valueSizeBytes = 0 + arg0ValueSer.calcSizeBytes(arg0) + arg1ValueSer.calcSizeBytes(arg1) +\n                arg2ValueSer.calcSizeBytes(arg2)\n        val sendBuf = ByteBuffer.allocate(staticPayload.size + valueSizeBytes)\n        sendBuf.order(ByteOrder.LITTLE_ENDIAN)\n        sendBuf.put(staticPayload)\n        arg0ValueSer.ser(sendBuf, arg0)\n        arg1ValueSer.ser(sendBuf, arg1)\n        arg2ValueSer.ser(sendBuf, arg2)\n        val sendBytes = sendBuf.array()\n\n        val receiveBytes = this.service!!.call(this.funcName!!, sendBytes)\n        val receiveBuf = ByteBuffer.wrap(receiveBytes)\n        receiveBuf.order(ByteOrder.LITTLE_ENDIAN)\n        receiveBuf.rewind()\n        val deserContext = TypeDeser.deserUntilM(receiveBuf)\n    }\n\n    companion object {\n        val staticPayload: ByteArray = Base64.getDecoder().decode(\"RElETAADcXF9\")\n    }\n}\n\ntypealias AnonFunc1ValueSer = FuncValueSer\n\nclass AnonFunc1(\n    funcName: String?,\n    service: SimpleIDLService?\n) : SimpleIDLFunc(funcName, service) {\n    suspend operator fun invoke(arg0: Name): Entry? {\n        val arg0ValueSer = NameValueSer\n        val valueSizeBytes = 0 + arg0ValueSer.calcSizeBytes(arg0)\n        val sendBuf = ByteBuffer.allocate(staticPayload.size + valueSizeBytes)\n        sendBuf.order(ByteOrder.LITTLE_ENDIAN)\n        sendBuf.put(staticPayload)\n        arg0ValueSer.ser(sendBuf, arg0)\n        val sendBytes = sendBuf.array()\n\n        val receiveBytes = this.service!!.query(this.funcName!!, sendBytes)\n        val receiveBuf = ByteBuffer.wrap(receiveBytes)\n        receiveBuf.order(ByteOrder.LITTLE_ENDIAN)\n        receiveBuf.rewind()\n        val deserContext = TypeDeser.deserUntilM(receiveBuf)\n        return senior.joinu.candid.serialize.OptValueSer( EntryValueSer ).deser(receiveBuf) as Entry?\n    }\n\n    companion object {\n        val staticPayload: ByteArray = Base64.getDecoder().decode(\"RElETAABcQ==\")\n    }\n}\n\nclass PhonebookService(\n    host: String,\n    canisterId: SimpleIDLPrincipal?,\n    keyPair: EdDSAKeyPair?,\n    apiVersion: String = \"v1\"\n) : SimpleIDLService(host, canisterId, keyPair, apiVersion) {\n    val insert: AnonFunc0 = AnonFunc0(\"insert\", this)\n\n    val lookup: AnonFunc1 = AnonFunc1(\"lookup\", this)\n}\n```\nwhich we then can use to interact with our deployed canister\n```kotlin\nval host = \"http://localhost:8000\"\nval keys = EdDSAKeyPair.generateInsecure()\nval canisterId = \"75hes-oqbaa-aaaaa-aaaaa-aaaaa-aaaaa-aaaaa-q\"\n\nval phonebook = PhonebookService(host, SimpleIDLPrincipal.fromText(canisterId), keys)\n\nphonebook.insert(\"test\", \"test desc\", BigInteger(\"12345\"))\nval entry = phonebook.lookup(\"test\")\n\ncheck(entry != null) { \"Entry not found\" } \n```\n\n\n### Pros\n* Idiomatic Kotlin\n* Complete type-safety\n* Asynchronous io with coroutines\n* Reflectionless single-allocation (de)serialization\n\n### Cons\n* Unstable\n\n### Type conversion rules\n| IDL | Kotlin |\n| --- | --- |\n| type T = \"existing type\" | typealias T = \"existing type\" |\n| int, nat | `BigInteger` |\n| int8, nat8 | `Byte` |\n| int16, nat16 | `Short` |\n| int32, nat32 | `Int` |\n| int64, nat64 | `Long` |\n| float32 | `Float` |\n| float64 | `Double` |\n| bool | `Boolean` |\n| text | `String` |\n| null | `Null` object |\n| reserved | `Reserved` object |\n| empty | `Empty` object |\n| opt T | `T?` |\n| vec T | `List\u003cT\u003e` |\n| type T = record { a: T1, b: T2 } | `data class T(val a: T1, val b: T2)` |\n| type T = variant { A, B: T1 } | `sealed class T { data class A: T(); data class B(val value: T1): T() }` |\n| type T = func (T1) -\u003e T2 | `class T { suspend operator fun invoke(arg0: T1): T2 }` |\n| type T = service { a: SomeFunc } | `class T { val a: SomeFunc }` |\n| principal | `Principal` class |\nUnnamed IDL types are transpiled into anonymous Kotlin types.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseniorjoinu%2Fcandid-kt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fseniorjoinu%2Fcandid-kt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseniorjoinu%2Fcandid-kt/lists"}