Android SDK
This page explains how to use App2App Android SDK to use Klip on your BApp.
Prerequisites
API 16: Android 4.1 (Jelly Bean) or higer
Java 8 or higher
Android Studio 3.0.0 or higher
Android Permission: Internet Permission
Environment Setup
Klip JavaScript SDK doesn't require a separate registration process and works in any environments where HTTP communication is possible. But since user's consent is received using Klip located in the More[…] tab in the mobile app KakaoTalk, you need to have KakaoTalk installed to make the requests.
You can find a guide for executing Klip Android SDK Sample App in README.md
.
1. Download Klip SDK
Download Klip Android SDK in Download.
2. Add Klip SDK Library
Option 1. Build Klip SDK and add to your project
Run Terminal at the location of downloaded Klip SDK project
Run the command
./gradlew :sdk:build
and build Klip SDK project (When building is complete, an AAR file is created at /sdk/build/outputs/aar/)Create a libs directory in the project
Copy the built AAR file to the project's libs directory
Add directory reference and dependency to the project's
build.gradle
If you need help with this document or Klip in general, please visit our [Developer Forum](https://forum.klaytn.com/c/klip-api/28).
Option 2. Import Klip SDK source code and add to your project
Run the project in Android Studio
Android Studio > File > New > Import Module
Select the sdk directory in the Klip SDK project downloaded in the Source Directory, and click Next
Copy
gradle.properties
in the Klip SDK project to your projectAdd the dependency setting in
build.gradle
of your project
Once the Klip SDK source is copied to your project, you can modify the library code yourself. This may not be a suitable option if you want to maintain single version library code. In this case, add the compiled AAR file as directed in Option 1.
3. Add Permission
In order to enable HTTP communication on Klip SDK, add android.permission.INTERNET
in the AndroidManifest.xml
file as shown below:
If you need help with this document or Klip in general, please visit our [Developer Forum](https://forum.klaytn.com/c/klip-api/28).
API
Overview
App2App API requests are made in the order: prepare
, request
, and getResult
.
prepare
is the step in which requests (from of a total of five) are definedrequest
is the step in which the function is called and the signing takes place on KlipgetResult
is the step in which the result is returned from the function call
In addition, getCardList
is a function provided for the convenience of BApp developers that returns a list of NFTs of a Klip user.
If you need help with this document or Klip in general, please visit our Developer Forum.
Klip.getInstance
Creates an instance to use Klip SDK.
Parameters
Name | Type | Description |
---|---|---|
context |
| Application context |
Return Value
Type | Description |
---|---|
| Klip instance |
Example
If you need help with this document or Klip in general, please visit our [Developer Forum](https://forum.klaytn.com/c/klip-api/28).
Klip.prepare
Prepares to process an App2App API request and issues a request key.
Request Objects
Connecting Klip(=authentication)
AuthRequest
Sending KLAY
KlayTxRequest
Sending Token
TokenTxRequest
Sending Card
CardTxRequest
Executing Contract
ContractTxRequest
Parameters
Name | Type | Description |
---|---|---|
request |
| Requested information depending on request type |
bappInfo |
| Information of the requested BApp |
callback |
| The callback function to obtain the response. If it's successful, it returns |
Throws
Type | Description |
---|---|
| Request exception (e.g. a required parameter was ommitted) |
Requesting consent to Klip users will return the data entered in request
and bappInfo
. The request key returned in the response serves as a key when requesting transactions to users, and is used with KlipSDK.shared.getResult and KlipSDK.shared.request.
Example 1. Obtaining User Information
Example 2. Sending KLAY
Example 3. Sending Tokens
Example 4. Sending Card
Example 5. Executing Contract
If you need help with this document or Klip in general, please visit our [Developer Forum](https://forum.klaytn.com/c/klip-api/28).
Klip.request
Requests authentification or signature using deep link. If the device doesn't have KakaoTalk installed, or the version of the installed KakaoTalk doesn't support Klip, it redirects automatically to the download page on Google Play. To implement the request step using QR code, please refer to QR Code Tutorial.
Parameters
Name | Type | Description |
---|---|---|
requestKey | String | Request number (Obtained from Klip Server) |
Throws
Type | Description |
---|---|
| Request exception (e.g. a required parameter was ommitted) |
Example
If you need help with this document or Klip in general, please visit our [Developer Forum](https://forum.klaytn.com/c/klip-api/28).
Klip.getResult
Returns the result of an App2App API request.
Parameters
Name | Type | Description |
---|---|---|
requestKey | String | Request number (Obtained from Klip Server) |
callback |
| The callback function to obtain the response. If it's successful, it returns |
Throws
Type | Description |
---|---|
| Request exception (e.g. a required parameter was ommitted) |
Example
If you need help with this document or Klip in general, please visit our [Developer Forum](https://forum.klaytn.com/c/klip-api/28).
Klip.getCardList
Returns a list of certain Cards of a user.
Parameters
Name | Type | Description |
---|---|---|
cardAddress | String | Address of the Card to retrieve |
userAddress | String | Address of the user to retrieve |
cursor | String | (optional) The pointer after which the next request will retrieve the next 100 items if the number of Cards exceeds 100. |
callback |
| The callback function to return the response. If it'successful, it returns |
Throws
Type | Description |
---|---|
| Request exception (e.g. when a required parameter is ommitted) |
Example
If you need help with this document or Klip in general, please visit our [Developer Forum](https://forum.klaytn.com/c/klip-api/28).
Error Code
You can see the error code via getErrorCode()
in KlipErrorResponse
, which is the fail response of KlipCallback
.
Http Status | Error Code | Description |
---|---|---|
- | - | Same as Klip REST API Error Code |
500 | 10 | Error in Klip SDK (e.g. HTTP c connection failure) |
500 | 21 | Error in Klip SDK (Klip REST API unsupported error code) |
500 | 22 | Error in Klip SDK (Klip protocol error) |
If you need help with this document or Klip in general, please visit our [Developer Forum](https://forum.klaytn.com/c/klip-api/28).
Last updated