Android OS μ΅μ μꡬμ¬ν
LunieWallet SDKλ μλλ‘μ΄λ API Level 23 μ΄μμ μ§μνλ μλλ‘μ΄λ OS λ²μ μ μ§μν©λλ€. 23 λ―Έλ§μ API Levelμ μ¬μ©νλ OS λ²μ μμλ SDKλ₯Ό ν¬ν¨ν μ΄ν리μΌμ΄μ μ΄ λ°νμμ μ μμ μΌλ‘ ꡬλλμ§ μμ μ μμ΅λλ€. κ° OS λ²μ λ³ μ§μ API Levelμ νμΈνλ €λ©΄ μλλ‘μ΄λ Release Note νμ΄μ§λ₯Ό μ°Έκ³ νμΈμ.
μλλ‘μ΄λ νλ‘μ νΈμ Wallet SDK μ°λνκΈ°
- Wallet SDKλ₯Ό λ€μ΄λ‘λ λ°μ λ€ lib ν΄λ νμμ μ μ₯ν©λλ€.
app/build.gradle
νμΌμ μλμ κ°μ΄ μμ‘΄μ±μ μΆκ°ν©λλ€.
...
dependencies {
implementation files('../lib/LunieWalletSDK.aar')
implementation "org.web3j:core:4.8.8-android"
implementation "com.squareup.retrofit2:retrofit:2.9.0"
implementation "com.squareup.retrofit2:converter-gson:2.9.0"
implementation "androidx.security:security-crypto:1.0.0"
implementation 'com.google.zxing:core:3.2.1'
}
- Nodit μ½μ μ μ μνμ¬ κ°μ ν λ€, Wallet SDK Guide νμ΄μ§λ₯Ό μ°Έκ³ νμ¬ Environment API Keyλ₯Ό λ°κΈν©λλ€.
- 3μμ λ°κΈλ°μ API Key μ¬μ©μ μν΄
config
νμΌμ μμ±ν ν Wallet API Keyλ₯Ό μ λ ₯ν©λλ€.config
νμΌμ κ²½λ‘λ λ€μκ³Ό κ°μ΅λλ€. serverλ₯Ό μ λ ₯νμ§ μλ κ²½μ°, defaultλ‘ Noditμ μλ²λ₯Ό μ΄μ©νκ² λ©λλ€.
projectFilePath/app/src/assets/lunie_wallet_configuration.json
{
"webview_server_url": "${WALLET_WEBVIEW_URL}", // If not entered, the Nodit server will be used as the default.
"api_server_url": "${WALLET_API_URL}", // If not entered, the Nodit server will be used as the default.
"wallet_api_key":"${WALLET_API_KEY}" // required field
}
SDK μ΄κΈ°ν λ° μ§κ° μμ±/λ‘λνκΈ°
- LunieWallet SDKλ₯Ό importν ν μλμ κ°μ΄ μ μΈνμ¬ SDKλ₯Ό μ΄κΈ°νν μ μμ΅λλ€.
Lunie.init(applicationContext)
- μλλ‘μ΄λ Keystoreμ μ μ₯λ μ§κ° μμ± μ΄λ ₯μ μ‘°νν ν, μ΄λ ₯μ΄ μμ κ²½μ° μ μ₯λ mnemonic ν΅ν΄ μ§κ°μ λ‘λνκ³ μ΄λ ₯μ΄ μλ κ²½μ° μ κ· μ§κ° Instanceλ₯Ό μμ±ν μ μμ΅λλ€.
//1. Check Wallet exist
val isAlreadySet = when (val result = LunieWallet.isAlreadySetWallet()) {
is LunieWalletResult.Success -> result.data
is LunieWalletResult.Fail -> {
Log.e("LunieWallet", result.error.message ?: "Unknown Error")
return
}
}
// Option 2-1. Load wallet from stored mnemonic in SecureLocalStorage if isAlreadySet ==1
val wallet = when (val result = LunieWallet.getInstanceSavedWallet()) {
is LunieWalletResult.Success -> result.data
is LunieWalletResult.Fail -> {
Log.e("LunieWallet", result.error.message ?: "Unknown Error")
return
}
}
// Option 2-2. Create new wallet if isAlreadySet == 0
val wallet = when (val result = LunieWallet.getInstanceNewWallet()) {
is LunieWalletResult.Success -> result.data
is LunieWalletResult.Fail -> {
Log.e("LunieWallet", result.error.message ?: "Unknown Error")
return
}
}
Wallet SDK API
Init For Use
λΌμ΄λΈλ¬λ¦¬ μ΄κΈ°ν ν¨μλ‘ LunieWallet SDK μ¬μ© μ νμλ‘ κ°μ₯ λ¨Όμ νΈμΆλμ΄μΌ ν©λλ€.
Lunie.init(applicationContext)
Create New Wallet
μλ‘μ΄ mnemonic keyλ₯Ό μμ±ν ν μ΄λ₯Ό μ΄μ©νμ¬ Wallet Instanceλ₯Ό μμ±ν©λλ€.
val wallet = when (val result = LunieWallet.getInstanceNewWallet()) {
is LunieWalletResult.Success -> result.data
is LunieWalletResult.Fail -> {
Log.e("LunieWallet", result.error.message ?: "Unknown Error")
return
}
}
Check Wallet Existence
νμ¬ λλ°μ΄μ€μ μ μ₯λ Wallet Instanceκ° μλμ§ νμΈν©λλ€.
val isAlreadySet = when (val result = LunieWallet.isAlreadySetWallet()) {
is LunieWalletResult.Success -> result.data
is LunieWalletResult.Fail -> {
Log.e("LunieWallet", result.error.message ?: "Unknown Error")
return
}
}
Load Wallet
νμ¬ λλ°μ΄μ€μ μ μ₯λ Wallet Instanceλ₯Ό νμΈν ν, Instanceκ° μ‘΄μ¬ν κ²½μ°, μ΄λ₯Ό Load ν©λλ€.
//1. Check Wallet existence
val isAlreadySet = when (val result = LunieWallet.isAlreadySetWallet()) {
is LunieWalletResult.Success -> result.data
is LunieWalletResult.Fail -> {
Log.e("LunieWallet", result.error.message ?: "Unknown Error")
return
}
}
if(isAlreadySet) {
// 2. Load saved wallet from SecureLocalStorage
val wallet = when (val result = LunieWallet.getInstanceSavedWallet()) {
is LunieWalletResult.Success -> result.data
is LunieWalletResult.Fail -> {
Log.e("LunieWallet", result.error.message ?: "Unknown Error")
return
}
}
} else {
// create new one
}
Recovery Wallet(MPC)
μ§κ°μ 볡ꡬνλ λ°©λ²μΌλ‘ λ°±μ ν΄ λ SecretSharesλ₯Ό μ΄μ©νμ¬ mnemonicμ 볡ꡬν©λλ€. κ·Έλ¦¬κ³ λ³΅κ΅¬ν mnemonicμ μ΄μ©νμ¬ Walletμ 볡ꡬν©λλ€.
// 1. Get secretShares for backup
val secretShares = when (val result = wallet.getSecretShares()) {
is LunieWalletResult.Success -> result.data
is LunieWalletResult.Fail -> {
Log.e("LunieWallet", result.error.message ?: "Unknown Error")
return
}
}
// 2. Recovery wallet from secretShares
val wallet = when (val result = LunieWallet.recoveryWalletFromSecretKeys(secretShares)) {
is LunieWalletResult.Success -> result.data
is LunieWalletResult.Fail -> {
Log.e("LunieWallet", result.error.message ?: "Unknown Error")
return
}
}
// 3. Recovery wallet from mnemonic
val wallet = when (val result = LunieWallet.recoveryWalletFromMnemonic(mnemonic)) {
is LunieWalletResult.Success -> result.data
is LunieWalletResult.Fail -> {
Log.e("LunieWallet", result.error.message ?: "Unknown Error")
return
}
}
Get Address
νΉμ μ£Όμμ λ€νΈμν¬λ₯Ό μ§μ νμ¬ ν΄λΉ μ§κ°μ΄ ν΄λΉ λ€νΈμν¬μ 보μ ν μμ°μ μ‘°νν©λλ€.
val network = NETWORK_THE_BALANCE
val address = when (val result = network.getAddress(wallet)) {
is LunieWalletResult.Success -> result.data
is LunieWalletResult.Fail -> {
Log.e("LunieWallet", result.error.message ?: "Unknown Error")
return
}
}
Get NFTs
νΉμ μ£Όμμ λ€νΈμν¬λ₯Ό μ§μ νμ¬ ν΄λΉ μ§κ°μ΄ ν΄λΉ λ€νΈμν¬μ 보μ ν NFTλ₯Ό μ‘°νν©λλ€.
val network = NETWORK_THE_BALANCE
val address = "0x9baCE0756260de6d28A89AcfcBf37BC512ff2333"
val (page, itemCount) = 1 to 10
val nftCollections = when (val result = network.getNFTs(address, page, itemCount)) {
is LunieWalletResult.Success -> result.data
is LunieWalletResult.Fail -> {
Log.e("LunieWallet", result.error.message ?: "Unknown Error")
return
}
}
Get Native Token
νΉμ μ£Όμμ λ€νΈμν¬λ₯Ό μ§μ νμ¬ ν΄λΉ μ§κ°μ΄ ν΄λΉ λ€νΈμν¬μ 보μ ν Native Tokenμ μ‘°νν©λλ€.
val network = NETWORK_THE_BALANCE
val address = "0x9baCE0756260de6d28A89AcfcBf37BC512ff2333"
val nativeTokenBalance = when (val result = network.getNativeToken(address)) {
is LunieWalletResult.Success -> result.data
is LunieWalletResult.Fail -> {
Log.e("LunieWallet", result.error.message ?: "Unknown Error")
return
}
}
Get Tokens
νΉμ μ£Όμμ λ€νΈμν¬λ₯Ό μ§μ νμ¬ ν΄λΉ μ§κ°μ΄ ν΄λΉ λ€νΈμν¬μ 보μ ν ERC20μ μ‘°νν©λλ€.
val network = NETWORK_THE_BALANCE
val address = "0x9baCE0756260de6d28A89AcfcBf37BC512ff2333"
val (page, itemCount) = 1 to 10
val tokenBalances = when (val result = network.getTokens(address, page, itemCount)) {
is LunieWalletResult.Success -> result.data
is LunieWalletResult.Fail -> {
Log.e("LunieWallet", result.error.message ?: "Unknown Error")
return
}
}
Get Gas Limit(NFT)
νΉμ μ£Όμμ λ€νΈμν¬λ₯Ό μ§μ νμ¬ ν΄λΉ μ§κ°μ΄ ν΄λΉ λ€νΈμν¬μμ NFTλ₯Ό μ μ‘νκΈ° μν΄ νμν GasLimitμ μ‘°νν©λλ€.
val network = NETWORK_THE_BALANCE
val toAddress = "0x9baCE0756260de6d28A89AcfcBf37BC512ff2333"
val gaslimit = when (val result = network.getGasLimit(lunieWallet, toAddress, nft)) {
is LunieWalletResult.Success -> result.data
is LunieWalletResult.Fail -> {
Log.e("LunieWallet", result.error.message ?: "Unknown Error")
return
}
}
Get Gas Limit(Token)
νΉμ μ£Όμμ λ€νΈμν¬λ₯Ό μ§μ νμ¬ ν΄λΉ μ§κ°μ΄ ν΄λΉ λ€νΈμν¬μμ Tokenλ₯Ό μ μ‘νκΈ° μν΄ νμν GasLimitμ μ‘°νν©λλ€.
val network = NETWORK_THE_BALANCE
val toAddress = "0x9baCE0756260de6d28A89AcfcBf37BC512ff2333"
val gaslimit = when (val result = network.getGasLimit(lunieWallet, toAddress, token, tokenAmount)) {
is LunieWalletResult.Success -> result.data
is LunieWalletResult.Fail -> {
Log.e("LunieWallet", result.error.message ?: "Unknown Error")
return
}
}
Get Gas Price
νΉμ μ£Όμμ λ€νΈμν¬λ₯Ό μ§μ νμ¬ ν΄λΉ μ§κ°μ΄ ν΄λΉ λ€νΈμν¬μμ Transferλ₯Ό μ€ννκΈ° μν΄ νμν GasPriceλ₯Ό μ‘°νν©λλ€.
val network = NETWORK_THE_BALANCE
val toAddress = "0x9baCE0756260de6d28A89AcfcBf37BC512ff2333"
val gasPrice = when (val result = network.getGasPrice()) {
is LunieWalletResult.Success -> result.data
is LunieWalletResult.Fail -> {
Log.e("LunieWallet", result.error.message ?: "Unknown Error")
return
}
}
Get Transaction Result By Hash
νΈλμμ μ Hashμ λ€νΈμν¬λ₯Ό μ§μ νμ¬ ν΄λΉ νΈλμμ μ μμΈ λ΄μμ μ‘°νν©λλ€.
val network = NETWORK_THE_BALANCE
val transactionHash = "0xf2edcf8f59cfce9350785f4d9cbdaa7ce76f6fabd4a3a96c3de82b91237973a1"
val transactionResult = when (val result = network.getTransactionResultByHash(transactionHash)) {
is LunieWalletResult.Success -> result.data
is LunieWalletResult.Fail -> {
Log.e("LunieWallet", result.error.message ?: "Unknown Error")
return
}
}
Get Account Transaction Results
νΉμ μ£Όμμ λ€νΈμν¬λ₯Ό μ§μ νμ¬ ν΄λΉ μ£Όμκ° ν¬ν¨λ νΈλμμ μ μ 체 λ΄μμ μ‘°νν©λλ€.
val network = NETWORK_THE_BALANCE
val address = "0x9baCE0756260de6d28A89AcfcBf37BC512ff2333"
val (page, itemCount) = 1 to 10
val transactionResults =
when (val result = network.getAccountTransactionResults(address, page, itemCount)) {
is LunieWalletResult.Success -> result.data
is LunieWalletResult.Fail -> {
Log.e("LunieWallet", result.error.message ?: "Unknown Error")
return
}
}
Get Token transaction From Address
νΉμ μ£Όμμ λ€νΈμν¬λ₯Ό μ§μ νμ¬ ν΄λΉ μ£Όμμ ERC20 νΈλμμ μ μμΈ λ΄μμ μ‘°νν©λλ€.
val network = NETWORK_THE_BALANCE
val address = "0x9baCE0756260de6d28A89AcfcBf37BC512ff2333"
val (page, itemCount) = 1 to 10
val transactionResults =
when (val result = network.getTokenTransactionFromAddress(address, page, itemCount)) {
is LunieWalletResult.Success -> result.data
is LunieWalletResult.Fail -> {
Log.e("LunieWallet", result.error.message ?: "Unknown Error")
return
}
}
Transfer NFT
νΉμ μ£Όμμ λ€νΈμν¬λ₯Ό μ§μ νμ¬ μ μ μ μ§κ°μ΄ 보μ ν NFTλ₯Ό νΉμ μ£Όμλ‘ μ μ‘νλ Transferλ₯Ό μ€νν©λλ€.
val network = NETWORK_THE_BALANCE
val tdAddress = "0x9baCE0756260de6d28A89AcfcBf37BC512ff2333"
val transactionHash = when (val result = network.transferNFT(lunieWallet, tdAddress, nft)) {
is LunieWalletResult.Success -> result.data
is LunieWalletResult.Fail -> {
Log.e("LunieWallet", result.error.message ?: "Unknown Error")
return
}
}
Transfer Token
νΉμ μ£Όμμ λ€νΈμν¬λ₯Ό μ§μ νμ¬ μ μ μ μ§κ°μ΄ 보μ ν ERC20μ νΉμ μ£Όμλ‘ μ μ‘νλ Transferλ₯Ό μ€νν©λλ€.
val network = NETWORK_THE_BALANCE
val tdAddress = "0x9baCE0756260de6d28A89AcfcBf37BC512ff2333"
val transactionHash =
when (val result = network.transferToken(lunieWallet, tdAddress, token, amount)) {
is LunieWalletResult.Success -> result.data
is LunieWalletResult.Fail -> {
Log.e("LunieWallet", result.error.message ?: "Unknown Error")
return
}
}
Wallet UI Component Setting
Wallet SDKλ νΈλ¦¬ν κ°λ°μ μ§μνκΈ° μν΄ κΈ°λ³Έμ μΈ WebViewλ₯Ό μ§μν©λλ€. μλ μ½λλ₯Ό μ΄μ©νμ¬ ν΄λΉ WebViewλ₯Ό νμΈν μ μμ΅λλ€.
// 1. WalletView Initial Setting
override fun onCreateView() {
...
lunieWalletView.init(wallet)
}
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.lambda256.walletsdk.LunieWalletView
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>