{"id":27994417,"url":"https://github.com/metaplex-foundation/solanakt","last_synced_at":"2025-05-08T19:11:32.956Z","repository":{"id":39789621,"uuid":"378984962","full_name":"metaplex-foundation/SolanaKT","owner":"metaplex-foundation","description":"This is a open source library on kotlin for Solana protocol.","archived":false,"fork":false,"pushed_at":"2023-11-24T16:18:07.000Z","size":714,"stargazers_count":73,"open_issues_count":18,"forks_count":38,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-02T16:12:17.392Z","etag":null,"topics":["android","cryptocurrency","kotlin","sol","solana"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/metaplex-foundation.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-06-21T15:52:15.000Z","updated_at":"2025-02-24T20:10:31.000Z","dependencies_parsed_at":"2024-01-12T19:47:13.674Z","dependency_job_id":"cfeacb56-f4ec-4a49-958e-0206418f68d4","html_url":"https://github.com/metaplex-foundation/SolanaKT","commit_stats":null,"previous_names":["ajamaica/solana.kt"],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metaplex-foundation%2FSolanaKT","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metaplex-foundation%2FSolanaKT/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metaplex-foundation%2FSolanaKT/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metaplex-foundation%2FSolanaKT/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/metaplex-foundation","download_url":"https://codeload.github.com/metaplex-foundation/SolanaKT/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253133123,"owners_count":21859112,"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","cryptocurrency","kotlin","sol","solana"],"created_at":"2025-05-08T19:11:32.305Z","updated_at":"2025-05-08T19:11:32.945Z","avatar_url":"https://github.com/metaplex-foundation.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ⛓️ Solana\n[![CI](https://github.com/metaplex-foundation/SolanaKT/actions/workflows/android.yml/badge.svg)](https://github.com/metaplex-foundation/SolanaKT/actions/workflows/android.yml)\n\nThis is an open-source library on Kotlin for Solana protocol.\n\nSolanaKT was built with modularity, portability, speed and efficiency in mind. \n\n# Features\n- [x] Sign and send transactions.\n- [x] Key pair generation\n- [x] RPC configuration.\n- [x] Few libraries requirement (okhttp3, bitcoinj, eddsa). RxKotlin is optional. No hidden JARs or shady dependencies.\n- [x] Fully tested\n- [x] Sockets\n- [x] Suspending functions support\n- [x] Bip39 seed phrase support\n\n## Installation\n\n### JitPack [![Release](https://jitpack.io/v/metaplex-foundation/SolanaKT.svg)](https://jitpack.io/#metaplex-foundation/SolanaKT)\n\nThe library is now available through [JitPack.io](https://jitpack.io/#metaplex-foundation/SolanaKT)\n\nFirst, add the JitPack repository to your build:\n\n```gradle\nrepositories {\n    ...\n    maven { url 'https://jitpack.io' }\n}\n```\n\nThen add the dependency to the 'build.gradle' file for your app/module:\n\n```gradle\ndependencies {\n    ...\n    implementation 'com.github.metaplex-foundation:SolanaKT:{version}'\n}\n```\n\n### Using GitHub Packages \n\nFirst get a Github Token from your [account settings](https://github.com/settings/tokens).\n\nInside settings.gradle add a maven repository:\n\n```gradle\nrepositories {\n\t...\n\tmaven {\n       name = \"GitHubPackages\"\n       url = \"https://maven.pkg.github.com/metaplex-foundation/SolanaKT\"\n       credentials {\n\t\t   username = \"\u003cYOUR_GITHUB_USERNAME\u003e\"\n\t\t   password = \"\u003cYOUR_GITHUB_TOKENS\u003e\"\n       }\n\t}\n}\n \n```\n\nThen at your build.gradle:\n\n```gradle\ndependencies {\n\t...\n\timplementation 'com.solana:solana:+' // Set version\n}\n```\n\nAfter that gradle sync.\n\n## Requirements\n\n- Android 19+\n\n# Usage\n\n## Initialization\n\nSet the NetworkingRouter and set up your environment. Use it to Initialize your solana object.\n\n```kotlin\nval endPoint = RPCEndpoint.devnetSolana\nval network = HttpNetworkingRouter(endPoint)\nval solana = Solana(network)\n```\n\n## Accounts or Signers\n\nThe library provides an Account protocol that acts as the signer for any operation. This account allows any client to implement their Wallet architecture and storage. Keep in mind that the secretKey is not handled by the protocol that's up to the implementation. \n\n```kotlin\ninterface Account {\n    val publicKey: PublicKey\n    fun sign(serializedMessage: ByteArray): ByteArray\n}\n```\n\nAn example implementation can be a HotAccount. SolanaKT comes with `HotAccount` which allows the creation and recovery from a standard Solana Mnemonic. This implementation does provide a secretKey object. The secretKey is held on a variable keep in mind that this might now be a secure way of permanent storage.\n\n```kotlin\nclass HotAccount : Account {\n\n    private var keyPair: TweetNaclFast.Signature.KeyPair\n\n    override val publicKey: PublicKey\n        get() = PublicKey(keyPair.publicKey)\n\n    private val secretKey: ByteArray\n        get() = keyPair.secretKey\n\n}\n```\n\nCreate Hot Account.\n\n```kotlin\nval account = HotAccount()\n\n```\n\nCreate Hot Account from the seed phrase.\n\n```kotlin\n\nval words = Arrays.asList(\"hint\", \"begin\", \"crowd\", \"dolphin\", \"drive\", \"render\", \"finger\", \"above\", \"sponsor\", \"prize\", \"runway\", \"invest\", \"dizzy\", \"pony\", \"bitter\", \"trial\", \"ignore\", \"crop\", \"please\", \"industry\", \"hockey\", \"wire\", \"use\", \"side\")\n\nval account = HotAccount.fromMnemonic(words, \"\", DerivationPath.BIP44_M_44H_501H_0H)\n\naccount.publicKey.toString() // G75kGJiizyFNdnvvHxkrBrcwLomGJT2CigdXnsYzrFHv\n\n```\n\nCreate a Hot Account from DerivationPath.DEPRECATED_M_501H_0H_0_0 seed phrase. Yes, we support Wallet Index and several accounts from the same Mnemonic. This is helpful for wallet creation. \n\n```kotlin\n\nval words = Arrays.asList(\"hint\", \"begin\", \"crowd\", \"dolphin\", \"drive\", \"render\", \"finger\", \"above\", \"sponsor\", \"prize\", \"runway\", \"invest\", \"dizzy\", \"pony\", \"bitter\", \"trial\", \"ignore\", \"crop\", \"please\", \"industry\", \"hockey\", \"wire\", \"use\", \"side\")\nval acc = HotAccount.fromMnemonic(words, \"\", DerivationPath.DEPRECATED_M_501H_0H_0_0)\n\n```\n\n## Seed Phrase Generation\n\nKotlinKT comes with Bip39 support. Do not confuse a seed phrase with an account. The Seed Phrase is a way to construct back the Account from a set of words.\n\n```kotlin\n\nval phrase24 = Mnemonic(WordCount.COUNT_24).phrase\nval phrase12 = Mnemonic(WordCount.COUNT_12).phrase\nval phrase21 = Mnemonic(WordCount.COUNT_21).phrase\n\n```\n\nIt's also possible to validate the Mnemonic\n\n```kotlin\nval phrase = Mnemonic(WordCount.COUNT_24).phrase\nMnemonic(phrase = phrase).validate()\n```\n\n## RPC api calls\n\nRPC requests are an application’s gateway to the Solana cluster. SolanaKT can be configured to the default free clusters (devnet, mainnet, testnet and custom)\n\n```kotlin\n\nsealed class RPCEndpoint(open val url: URL, open val urlWebSocket: URL, open val network: Network) {\n\n    object mainnetBetaSerum: RPCEndpoint(\n        URL(\"https://solana-api.projectserum.com\"), URL(\"https://solana-api.projectserum.com\"), Network.mainnetBeta\n    )\n\n    object mainnetBetaSolana: RPCEndpoint(\n        URL(\"https://api.mainnet-beta.solana.com\"), URL(\"https://api.mainnet-beta.solana.com\"), Network.mainnetBeta\n    )\n\n    object devnetSolana: RPCEndpoint(\n        URL(\"https://api.devnet.solana.com\"), URL(\"https://api.devnet.solana.com\"), Network.devnet\n    )\n\n    object testnetSolana: RPCEndpoint(\n        URL(\"https://testnet.solana.com\"), URL(\"https://testnet.solana.com\"),Network.testnet\n    )\n\n}\n\n```\n\nWe support [45](https://github.com/ajamaica/SolanaKT/tree/master/solana/src/main/java/com/solana/api \"Check the Api folder\") rpc api calls. The RPCs return a result. You can `.getOrThrow()`, `exceptionOrNull()`, `.map`, `.mapCatching` `.getOrNull()` `.getOrDefault` depending of your scenario. \n\nGet Balance\n\n```kotlin\nval balance = solana.api.getBalance(PublicKey(\"FzhfekYF625gqAemjNZxjgTZGwfJpavMZpXCLFdypRFD\")).getOrThrow()\n```\n\nThe API methods such as `getAccountInfo` accept a KSerializer object (from kotlin.serialization) that tells the networking layer how to unpack the data received from the underlying RPC call. This serializer must account for both any nested JSON returned by the underlying RPC call, as well as the (likely Base64) encoded account data contained within. While any custom serializer can be used, the library provides several composable serializers to aid in unpacking common Solana calls. For example:\n\nGet Accounts info.\n\n```kotlin\nval serializer = AccountInfoSerializer(BorshAsBase64JsonArraySerializer((AccountInfoData.serializer())))\nval account = solana.api.getAccountInfo(serializer, PublicKey(\"8hoBQbSFKfDK3Mo7Wwc15Pp2bbkYuJE8TdQmnHNDjXoQ\")).getOrThrow()\n```\n\n\n## Actions\n\nActions are predefined program interfaces that construct the required inputs for the most common tasks in Solana ecosystems. You can see them as a bunch of code that implements Solana tasks using RPC calls.\n\nWe support 9.\n- closeTokenAccount: Closes token account\n- getTokenWallets: get token accounts\n- createAssociatedTokenAccount: Opens associated token account\n- sendSOL: Sends SOL native token\n- createTokenAccount: Opens token account\n- sendSPLTokens: Sends tokens\n- findSPLTokenDestinationAddress: Finds the address of a token of an address\n- **serializeAndSendWithFee**: Serializes and signs the transaction. Then it is sent to the blockchain.\n- getMintData: Get mint data for token\n\n### Example\n\nSending sol\n\n```kotlin\nval account = HotAccount() // Should be founded\nval toPublicKey = PublicKey(\"3h1zGmCwsRJnVk5BuRNMLsPaQu1y2aqXqXDWYCgrp5UG\")\nsolana.action.sendSOL(account, toPublicKey, 1) { result -\u003e\n    result.onSuccess {\n        emitter.onSuccess(it)\n    }.onFailure {\n        emitter.onError(it)\n    }\n}\n```\n\n## ⛓️ RxSolana\n\nWe also include support for RxKotlin in the RxSolana package. \n\nOne example using RxKotlin\n```koltin\nval solana = Solana(HttpNetworkingRouter(RPCEndpoint.devnetSolana))\nsolana.api.getVersion().doOnSuccess { \n    // SolanaVersion is available here\n}\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetaplex-foundation%2Fsolanakt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmetaplex-foundation%2Fsolanakt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetaplex-foundation%2Fsolanakt/lists"}