DexonWalletSDK 1.0.0

DexonWalletSDK 1.0.0

Scott Chou 维护。



DexonWalletSDK

CI Status Version License Platform

示例

要运行示例项目,请克隆仓库,然后在 Example 目录中首先运行 pod install

系统要求

  • 部署目标 iOS 9.0+
  • Xcode 10.0+
  • swift 4.2+

安装

DexonWalletSDK 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中

pod 'DexonWalletSDK'

为您的应用程序添加方案

打开 Info.plist 并添加您的方案

<key>CFBundleURLTypes</key>
<array>
	<dict>
		<key>CFBundleURLSchemes</key>
		<array>
			<string>{your_scheme}</string>
		</array>
	</dict>
</array>

处理回调

在您的AppDelegate中,添加以下代码

import DexonWalletSDK

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Handle wallet results
    if let url = launchOptions?[.url] as? URL {
        return dexonWallet.handleCallback(url: url)
    }
    
    ...
    
    return true
}

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
    // Handle wallet results
    return dexonWallet.handleCallback(url: url)
}

特性

请求账号

import DexonWalletSDK

let dexonWallet = DexonWalletSDK(name: "SDK-Example", callbackScheme: "example-dexon-wallet", blockchain: .dexon)
dexonWallet.requestAccounts { (result) in
    switch result {
    case .success(let address):
        debugPrint(address)
    case .failure(let error):
        debugPrint(error)
    }
}

签名消息 / 个人消息 / 文本消息

import DexonWalletSDK

let dexonWallet = DexonWalletSDK(name: "SDK-Example", callbackScheme: "example-dexon-wallet", blockchain: .dexon)
dexonWallet.sign(message: "any message you wanna sign") { (result) in
    switch result {
    case .success(let signature):
        debugPrint(signature)
    case .failure(let error)
        debugPrint(error)
    }
}

// For personal message
// dexonWallet.sign(personalMessage:)

// For typed message
// dexonWallet.sign(typedMessage:)

发送交易

import DexonWalletSDK

let dexonWallet = DexonWalletSDK(name: "SDK-Example", callbackScheme: "example-dexon-wallet", blockchain: .dexon)
dexonWallet.sendTransaction(toAddress: "0xb25d07735d5B9B5601C549e901b04bd3A5Af93a6", amount: 1) { (result) in
    switch result {
    case .success(let tx):
        debugPrint(tx)
    case .failure(let error):
        debugPrint(error)
    }
}

Web3 Swift 集成

在您的Podfile中添加一行,然后运行pod install

pod 'DexonWalletSDK/Web3'

然后使用DexonWallet对象初始化web3。

import DexonWalletSDK
import web3swift

let dexonRpcURL = URL(string: "https://api-testnet.dexscan.org/v1/network/rpc")!
web3 = Web3(dexonRpcURL: dexonRpcURL, dexonWallet: dexonWallet, network: .dexonTestnet)

请求账号

web3.eth.getAccountsPromise().done { addresses in
    debugPrint(addresses)
}.catch { error in
    debugPrint(error)
}

发送私人信息

web3.personal.signPersonalMessagePromise(message: messageData, from: Address(fromAddress)).done { signature in
    debugPrint(signature)
}.catch { error in
    debugPrint(error)
}

发送交易

var transaction = EthereumTransaction(to: Address("0x18d9D6d8761fc5E81712e3A0C49A5906AC96bF90"), data: data ?? Data(), options: .default)
transaction.value = BigUInt(1_000_000_000) // 1 Gwei
    
var options = Web3Options()
options.from = Address("0x18d9D6d8761fc5E81712e3A0C49A5906AC96bF90")
options.gasPrice = BigUInt(10)
options.gasLimit = BigUInt(21000)
    
web3.eth.sendTransactionPromise(transaction, options: options).done { result in
    debugPrint("tx: \(result.hash)")
}.catch { error in
    debugPrint(error)
}

许可

DexonWalletSDK 在MIT许可证下可用。有关更多信息,请参阅LICENSE文件。

感谢

TrustSDK-iOS 和 MathWalletSDK-iOS