Swift 是一种强类型语言,长期以来不仅用于 iOS 开发。Apple 正在积极将其推广到新的平台,如今它几乎可以用于任何任务。因此,此实现提供了 TVM (toncoin, everscale, venom, gosh) SDK 在多个平台上的工作,包括移动电话的原生平台。请允许我提醒您,swift 也可以为 android 构建。
操作系统 | 结果 |
---|---|
MacOS | ✅ |
Linux | ✅ |
iOS | ✅ |
Windows | 即将推出 |
您需要在这里获取 API-KEY https://dashboard.evercloud.dev
所有请求都是异步的
import EverscaleClientSwift
var config: TSDKClientConfig = .init()
config.network = TSDKNetworkConfig(endpoints: ["https://net.ton.dev"])
let client: TSDKClientModule = .init(config: config)
// Crypto
client.crypto.factorize(TSDKParamsOfFactorize(composite: "17ED48941A08F981")) { (response) in
print(response.result?.factors)
}
// Boc
let payload: TSDKParamsOfParse = .init(boc: "te6ccgEBAQEAWAAAq2n+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAE/zMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzSsG8DgAAAAAjuOu9NAL7BxYpA")
client.boc.parse_message(payload) { (response) in
if let result = response.result, let parsed: [String: Any] = result.parsed.toDictionary() {
print(parsed["id"])
print(parsed["src"])
print(parsed["dst"])
}
}
client.crypto.factorize(TSDKParamsOfFactorize(composite: "17ED48941A08F981")) { (response) in
if let error = response.error {
print(error.data.toJSON())
print(error.code)
}
}
cd everscale-client-swift
bash scripts/install_tonsdk.sh
将 Rust 安装到您的操作系统
cd ./SDK
cargo update
cargo build --release
复制或创建动态库的符号链接
macOS
./SDK/target/release/libton_client.dylib
到
/usr/local/lib/libton_client.dylib
Linux
./SDK/target/release/libton_client.so
到
/usr/lib/libton_client.so
创建 pkgConfig 文件
macOS
/usr/local/lib/pkgconfig/libton_client.pc
prefix=/usr/local
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/lib
Name: ton_client
Description: ton_client
Version: 1.0.0
Cflags: -I${includedir}
Libs: -L${libdir} -lton_client
Linux
/usr/lib/pkgconfig/libton_client.pc
prefix=/usr
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/lib
Name: ton_client
Description: ton_client
Version: 1.0.0
Cflags: -I${includedir}
Libs: -L${libdir} -lton_client
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh || true && \
source ~/.profile
rustup target add aarch64-apple-ios x86_64-apple-ios || true && \
cargo install cargo-lipo
转到您的项目文件夹并
git clone https://github.com/tonlabs/SDK.git || true && \
cd ./SDK
git pull --ff-only || true && \
cargo update || true && \
cargo lipo --release
在 xcode 中,文件 > 添加文件到 “您的项目名称” 导航到 ./SDK/ton_client/tonclient.h
创建桥接文件。在 xcode 中,文件 > 新建 > 文件,选择 Header File,设置名称,例如 Tonclient-Bridging-Header.h
并添加
#include <stdbool.h>
#import "tonclient.h"
像这样
#ifndef Tonclient_Bridging_Header_h
#define Tonclient_Bridging_Header_h
#include <stdbool.h>
#import "tonclient.h"
#endif
请为您的 xcode 方案设置自定义工作目录为项目文件夹。这对于此库文件夹的相对路径 "./" 是必要的。您可以使用 xcode 编辑方案菜单 Product > Scheme > Edit Scheme 菜单 Run 子菜单 Options 启用复选框 “Use custom directory” 并添加自定义工作目录。
或者,如果上述变体不可用,则在文件 path_to_this_library/.swiftpm/xcode/xcshareddata/xcschemes/TonClientSwift.xcscheme 中,将标签 "LaunchAction" 设置为此库的绝对路径,并带有选项
useCustomWorkingDirectory = "YES"
customWorkingDirectory = "/path_to_this_library"
server_address=https://net.ton.dev
giver_address=0:653b9a6452c7a982c6dc92b2da9eba832ade1c467699ebb3b43dca6d77b780dd
giver_abi_name=Giver
giver_function=grant
可选: 如果您需要,为测试安装本地 NodeSE
server_address=https://:80
giver_abi_name=GiverNodeSE_v2
giver_amount=10000000000
cd everscale-client-swift
bash api_generate.sh