iotex-antenna-swift
iotex-antenna-swift 是我们的软件开发工具包(SDK),允许您使用 gRPC 连接与本地或远程的 iotex 区块链节点进行交互。IoTeX 正在构建下一代由可扩展性和隐私驱动的区块链构建的物联网去中心化网络。有关详细信息,请参阅 IoTeX 白皮书。
开发
更新 Proto
mkdir protogen
protoc \
proto/api/api.proto proto/rpc/rpc.proto \
proto/types/action.proto proto/types/blockchain.proto proto/types/consensus.proto \
proto/types/endorsement.proto proto/types/genesis.proto proto/types/node.proto \
--swift_opt=Visibility=Public \
--swift_out=protogen \
--swiftgrpc_out=Visibility=Public,Client=true,Server=false:./protogen
find protogen -name "*.swift" -exec mv {} Sources/Protogen \;
rm -rf protogen
安装
pod 'iotex-antenna-swift', '~> 0.1'
示例
// create account from private key
let account = try Account(privateKey: "0806c458b262edd333a191e92f561aff338211ee3e18ab315a074a2d82aa343f")
let iotx = try IOTX(provider: "api.testnet.iotex.one:443", secure: true)
// query account meta
let response = try iotx.currentProvider().getAccount(Iotexapi_GetAccountRequest.with {
$0.address = account.address
})
print(response)
// transfer IOTX
let hash = try iotx.transfer(TransferRequest(
nonce: nil, gasLimit: 100000, gasPrice: "10000000000000", account: account,
recipient: "io13zt8sznez2pf0q0hqdz2hyl938wak2fsjgdeml", amount: "1000000000000000000", payload: "".data(using: .utf8)!
))
print(hash)