Android / Kotlin
Get Started or Add to an Existing Project
Getting started with Kin is incredibly straightforward. Just follow the steps below to start transacting with Kin in your app.
Installation
In your root build.gradle or settings.gradle, make sure you've included jitpack:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
And add the dependency, normally in the module-level build.gradle:
dependencies {
implementation 'com.github.kin-labs:kinetic-android-sdk:1.0.0-rc.5'
}
Instantiate the Kinetic Client
The Kinetic Client will give you access to all the methods you need to work with Kin on the blockchain.
We recommend starting with Devnet before moving on to Mainnet.
The Kinetic SDK uses Kotlin suspend functions to perform asynchronous network calls. We recommend calling these from within a CoroutineScope as follows where necessary. As there are many ways to handle asynchronous code in Kotlin, we will not include the CoroutineScope in every piece of sample code, but it may be necessary in your implementation.
import org.kin.kinetic.KineticSdk
CoroutineScope(Dispatchers.IO).launch {
val kinetic = KineticSdk.setup(
"https://sandbox.kinetic.host",
"devnet",
1
)
}
Don't have an App Index? Register your app on our Developer Portal so you can get your App Index that allows you to transact with our SDKs and earn via the KRE.
Register Your App
Learn how to register your app on the Kin Developer Portal
Kin Dev Portal
Go straight to the Kin Developer Portal and get started
While you're waiting for confirmation of your App Index, use 1
on devnet so you can get started.
Create Account
You can create accounts randomly or from existing mnemonics or secret keys. Below, we'll make a keypair and use that for creating an account on the blockchain.
You can also generate keypairs and create accounts on devnet via the Kin Laboratory.
val owner = Keypair.random()
val transaction = kinetic.createAccount(owner)
Close Account
It's good practice to close unneeded accounts. You can only close accounts that you have created and are currently empty.
val transaction = kinetic.closeAccount(owner.publicKey)
Check Balance
Check a user balance by passing in the public key of the account you want to check.
The response object includes your total Kin balance as well as detailing all of the Mints and Tokens held by that Public Key.
val balance = kinetic.getBalance(owner.publicKey).balance
Airdrop Funds (devnet)
Send some test funds to a specific Public Key on Devnet.
Or visit the Kin Laboratory to do it with a click!
val airdropSignature = kinetic.requestAirdrop(owner.publicKey).signature
Transfer Kin
Transfer Kin from a Keypair to any Public Key.
Make sure to include your Transaction Type if you want it to count towards the KRE.
val txSignature = kinetic.makeTransfer(
"5000",
"BQJi5K2s4SDDbed1ArpXjb6n7yVUfM34ym9a179MAqVo",
owner,
type = KinBinaryMemo.TransactionType.Spend
).signature
Get Transaction Details
Get the details of any transaction by passing in the transaction signature.
val transactionDetails = kinetic.getTransaction(txSignature)
Get Solana Explorer URL
val explorerURL = kinetic.getExplorerUrl("account or transaction id string")
Get Account History
Get the full transaction history of any account by passing in the account's Public Key.
val accountHistory = kinetic.getHistory(owner.publicKey)
Get Account Info
Easily get the main info of any account by passing in the account's Public Key.
val accountInfo = kinetic.getAccountInfo(owner.publicKey)
Get Token Accounts
Get the full list of Token Accounts held by a Keypair on Solana.
val tokenAccounts = kinetic.getTokenAccounts(owner.publicKey)
Demos and Starter Kits
Created to help get you up and running as quickly as possible, these projects can be a great reference point when you get stuck or even a starter for your own project. Happy coding!
Coming soon!
Ready for Production?
If your app is ready for production, this is the place for you!
Production
Get your app ready and running on the Solana Mainnet so you can earn Kin via the KRE
Earn Kin via the KRE
Kin Rewards Engine
Earn Kin by using it in your App
Contribute
Kinetic Android SDK
Want to contribute to the Kinetic Android SDK?
What If I Get Stuck?
Getting Help
Stuck? No problem, we have an amazing community waiting to help out.
Developer Discord
Join our fantastic developer community.
Developer Best Practices
Once you're ready to code, have a quick look at our Developer Best Practices where we cover some useful topics that you'll want to keep in mind as you build out your Kin application.
Best Practices
Some key information you'll want to keep in mind as you develop your App
Upgrading to Kinetic from Agora?
Upgrading to Kinetic
Here's some extra info that will help you complete your upgrade.
Agora
Prior to the release of Kinetic, our Kin SDKs were powered by a now-deprecated technology called Agora. Check out our old docs site if you want to see more.
Here, we will outline the key API changes from the old version of our SDK to the new Kinetic version.
General notes
- For methods that request Kin be transferred,
amount
is the amount of Kin, not quarks. - Response objects from requests have updated / changed.
Instantiate the Kin Client
// Kinetic
import org.kin.kinetic.KineticSdk
CoroutineScope(Dispatchers.IO).launch {
val kinetic = KineticSdk.setup(
"https://sandbox.kinetic.host",
"devnet",
1
)
}
// Agora
import org.kin.sdk.base.*
val environment: KinEnvironment = KinEnvironment.Agora.Builder(NetworkEnvironment.DevNet)
.setAppInfoProvider(object : AppInfoProvider {
override val appInfo: AppInfo =
AppInfo(
AppIdx(1),
KinAccount.Id("public key"),
"App Name",
R.mipmap.appIcon
)
override fun getPassthroughAppUserCredentials(): AppUserCreds {
return AppUserCreds("demo_app_uid", "demo_app_user_passkey")
}
})
.build()
Create Account
// Kinetic
val owner = Keypair.random()
val transaction = kinetic.createAccount(owner)
// Agora
val accountContext = KinAccountContext.Builder(environment)
.createNewAccount()
.build()
Check Balance
// Kinetic
val balance = kinetic.getBalance(owner.publicKey).balance
// Agora
val balanceObserver = accountContext.observeBalance(ObservationMode.Active)
balanceObserver.add { kinBalance: KinBalance ->
val balance = kinBalance.amount.value.toInt()
}
Transfer Kin
// Kinetic
val txSignature = kinetic.makeTransfer(
"5000",
"BQJi5K2s4SDDbed1ArpXjb6n7yVUfM34ym9a179MAqVo",
owner,
type = KinBinaryMemo.TransactionType.Spend
).signature
// Agora
accountContext.sendKinPayment(
KinAmount(5000),
KinAccount.Id("BQJi5K2s4SDDbed1ArpXjb6n7yVUfM34ym9a179MAqVo"),
memo
)
.then(
onResolved = { kinPayment ->
val txSignature = Base58.encode(kinPayment.id.transactionHash.rawValue)
},
onRejected = { t ->
// Handle error
}
)
Was this page helpful to you?
Provide feedback