NANJ SDK 项目
代码名称:FIERCE TIGER## 特点
- 创建 NANJ 钱包
- 通过私钥/密钥存储导入 NANJ 钱包
- 从 NANJ 钱包导出私钥/密钥存储
- 转账 NANJ 代币
- 交易历史记录
- 获取 NANJCOIN 在 JPY 中的汇率
- 通过二维码捕获钱包地址
- 通过 NFC 轻触捕获钱包地址
- 获取特定 ERC20 代币转账的最小允许金额
- 获取特定 ERC20 代币转账的最高交易费
- 获取 NANJCOIN 在 USD 中的汇率
要求
- iOS 10.0+
- Xcode 9.3+
- Swift 3.1+
交流
安装
CocoaPods 是针对 Cocoa 项目的依赖管理器。您可以使用以下命令安装它
$ gem install cocoapods
要使用 CocoaPods 将 NANJFrameworks
集成到您的 Xcode 项目中,请在您的 Podfile
中指定它
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!
target '<Your Target Name>' do
pod 'NANJFrameworks'
end
然后,运行以下命令
$ pod install
使用方法
初始化
- 在
AppDelegate.swift
中导入NANJFrameworks
import NANJFrameworks
- 向 didFinishLaunchingWithOptions 方法中添加以下行
//Set Development Mode
NANJWalletManager.shared.setDevelopmentMode(isDevelopment: true)
NANJWalletManager.shared.startConfig(appId: "AppId", appSecret: "AppSecret", coinName: "CoinName")
环境设置
开发模式与预发布服务器
NANJWalletManager.shared.setDevelopmentMode(isDevelopment: true)
生产模式与生产服务器
NANJWalletManager.shared.setDevelopmentMode(isDevelopment: false)
注意:请在调用 startConfig
之前调用该方法
创建新钱包
要创建新钱包,请通过 NANJWalletManager 的共享实例使用 CreateWallet 方法
NANJWalletManager.shared.createWallet(password:"Password")
要接收钱包创建成功的事件,请将 delegate
分配给 NANJWalletManager
NANJWalletManager.shared.delegate = self
一旦创建钱包,代理将调用该方法
func didCreatingWallet(wallet: NANJWallet?)
一旦创建钱包,代理将调用该方法
func didCreateWallet(wallet: NANJWallet?, error: Error?) {
导入钱包
- 使用私钥
NANJWalletManager.shared.importWallet(privateKey: "Private Key")
- 使用密钥库(请注意,我们需要密码来解锁密钥库)
NANJWalletManager.shared.importWallet(keyStore "Key Store", password "Password")
如果钱包导入成功,将通过方法调用代理
func didImportWallet(wallet: NANJWallet?, error: Error?)
成功导入返回 wallet
,有错误返回 error
。
导出钱包
- 导出私钥
NANJWalletManager.shared.exportPrivateKey(wallet: "NANJWallet")
Private key
将通过代理的方法接收
func didExportPrivatekey(wallet: NANJWallet, privateKey: String?, error: Error?, error: nil)
成功导出返回 String
privateKey
。
有错误返回 Error
。
- 导出密钥库
NANJWalletManager.shared.exportKeystore(wallet: "NANJWallet", password: "Password")
类似于导出私钥,导出密钥库将通过代理方法的返回
func didExportKeystore(wallet: NANJWallet, keyStore: String?, error: Error?)
转帐 NANJCOIN
要向特定地址发送 NANJ Coin,请使用下面的代码行来发送 NANJWallet
实例
self.currentWallet = NANJWalletManager.shared.getCurrentWallet()
self.currentWallet?.delegate = self
self.currentWallet?.sendNANJ(toAddress: "NANJ Address", amount: "Amount send")
发送 NANJCoin 的结果将通过方法的 delegate
确认
func didSendNANJCompleted(transaction: NANJTransaction?)
或通过错误持久化
func didSendNANJError(error: String?)
获取 NANJCOIN 的 JPY 收益率
self.currentWallet?.delegate = self
self.currentWallet?.getNANJRate()
NANJ 收益率将通过代理方法返回
@objc optional func didGetNANJRate(rate: Double)
获取 NANJCOIN 的 JPY 或 USD 收益率
self.walletManager.delegate = self
self.walletManager.getNANJRateWith(currency: string)
在方法 getNANJRateWith
中输入货币符号
美元:'usd'
和 日元:'jpy'
NANJ 收益率将通过代理方法返回
@objc optional func didGetNANJCurrencyRate(rate: Double, currency: String)
获取交易清单
self.currentWallet?.delegate = self
self.currentWallet?.getTransactionList(page: 1, offset: 20)
通过代理调用接收
func didGetTransactionList(transactions: Array<NANJTransaction>?)
NANJTransaction 类
public class NANJTransaction: NSObject {
public let id: UInt?
public let txHash: String?
public let status: Int?
public let from: String?
public let to: String?
public let value: String?
public let message: String?
public let txFee: String?
public let timestamp: UInt?
public let tokenSymbol: String?
...
}
获取每笔交易的最小金额和最大交易费
设置当前 ERC20 代币后,SDK 可以获取最小金额和最大交易费。这个最小金额和最大费用将适用于所选的 ERC20 代币。
获取每笔交易的最小金额
NANJWalletManager.shared.getMinimumAmount()
获取每笔交易的最大费用
NANJWalletManager.shared.getMaxFee()
慈悲 SDK 支持多个 ERC20/ERC223
检索支持的 ERC20/ERC223
let arrayOfERC20 = NANJWalletManager.shared.getListERC20Support()
通过 ERC20 标识符检索支持的 ERC20/ERC223
let idERC20 = 1
let arrayOfERC20 = NANJWalletManager.shared.getERC20Support(idERC20)
使用 ERC20/ERC223
let idERC20 = 1
NANJWalletManager.shared.setCurrentERC20Support(idERC20)
检索当前的 ERC20/ERC223
NANJWalletManager.shared.getCurrentERC20Support(idERC20)
此功能允许 SDK 在多个 ERC20/ERC223 币之间切换
作者
NANJCOIN, [email protected]
许可协议
请在此链接阅读我们的许可协议。 许可协议您可以选择语言为 JP/EN。