Swift Client for Free Ton SDK
Swift is a strongly typed language that has long been used not only for iOS development. Apple is actively promoting it to new platforms and today it can be used for almost any task. Thanks to this, this implementation provides the work of TonSDK on many platforms at once, including the native one for mobile phones. Let me remind you that swift can also be built for android.
OS | Result |
---|---|
MacOS | ✅ |
Linux | ✅ |
iOS | ✅ |
Windows | Soon |
Usage
All requests are async
Errors
Setup TONSDK For Linux and MacOS
Install sdk with bash script
- This download TON-SDK to current dirrectory, compile it and add library symlinks to your system
- note: then you can update the TON-SDK version simply by running these commands:
cd ton-client-swift/TON-SDK
git pull
cargo update
cargo build --release
Manual install sdk ( if you have any problem with script install_tonsdk.sh )
SPOILER: Manual installation
-
Install Rust to your OS
-
git clone https://github.com/tonlabs/TON-SDK
-
cd ./TON-SDK
-
cargo update
-
cargo build --release
-
copy or create symlink of dynamic library
macOS :
./TON-SDK/target/release/libton_client.dylib
to
/usr/local/lib/libton_client.dylibLinux :
./TON-SDK/target/release/libton_client.so
to
/usr/lib/libton_client.so -
Create pkgConfig file :
macOS :
/usr/local/lib/pkgconfig/libton_client.pc
Linux:
/usr/lib/pkgconfig/libton_client.pc
- Copy or create symlink of file
/TON-SDK/ton_client/client/tonclient.h
to
MacOS:
/usr/local/include/tonclient.h
Linux:
/usr/include/tonclient.h
Setup TONSDK For iOS
- Install Rust
- Install "cargo lipo"
- Build TON-SDK for iOS
Go to your project folder and:
⚠️ Wait installation
-
In xcode File > Add files to "Name Your Project" navigate to ./TON-SDK/ton_client/tonclient.h
-
Create bridge. In xcode File > New > File, select Header File, set name for example Tonclient-Bridging-Header.h
and add
#include <stdbool.h>
#import "tonclient.h"
like this:
- Add path to Tonclient-Bridging-Header.h $(PROJECT_DIR)/Tonclient-Bridging-Header.h
- Add path to search for libraries ( path to directory withlibton_client.a ) $(PROJECT_DIR)/TON-SDK/target/universal/release
- File > Swift Packages > Add Package Dependency https://github.com/nerzh/ton-client-swift
- Build project ...
Tests
If you use Xcode for Test
Please, set custom working directory to project folder for your xcode scheme. This is necessary for the relative path "./" to this library folders.
You may change it with the xcode edit scheme menu Product > Scheme > Edit Scheme menu Run submenu Options enable checkbox "Use custom directory" and add custom working directory.
Or if above variant not available, then inside file path_to_this_library/.swiftpm/xcode/xcshareddata/xcschemes/TonClientSwift.xcscheme
set to tag "LaunchAction" absolute path to this library with options:
useCustomWorkingDirectory = "YES"
customWorkingDirectory = "/path_to_this_library"
Tests
- inside root directory of ton-client-swift create .env.debug file with
NET TON DEV
server_address=https://net.ton.dev
giver_address=0:653b9a6452c7a982c6dc92b2da9eba832ade1c467699ebb3b43dca6d77b780dd
giver_abi_name=Giver
giver_function=grant
Optional: Install locale NodeSE for tests if you needed:
- launch docker
- docker run -d --name local-node -p 80:80 tonlabs/local-node
nodeSE will start on localhost:80
server_address=http://localhost:80
giver_abi_name=GiverNodeSE_v2
giver_amount=10000000000
- Run Tests
MacOS:
Run Tests inside Xcode
Linux:
swift test --generate-linuxmain
swift test --enable-test-discovery