Swift Client for TVM SDK (toncoin, everscale, venom, gosh)
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 TVM (toncoin, everscale, venom, gosh) SDK on many platforms at once, including the native one for mobile phones. Let me remind you that swift can also be built for android.
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"])
}
}
Errors
client.crypto.factorize(TSDKParamsOfFactorize(composite: "17ED48941A08F981")) { (response) in
if let error = response.error {
print(error.data.toJSON())
print(error.code)
}
}
Setup TONSDK For Linux and MacOS
Install sdk with bash script
This download SDK to current dirrectory, compile it and add library symlinks to your system
cd everscale-client-swift
For install or update the SDK version simply by running these command
bash scripts/install_tonsdk.sh
Manual install sdk ( if you have any problem with script install_tonsdk.sh )
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 everscale-client-swift create .env.debug file with
NET TON DEV
Swift Client for TVM SDK (toncoin, everscale, venom, gosh)
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 TVM (toncoin, everscale, venom, gosh) SDK on many platforms at once, including the native one for mobile phones. Let me remind you that swift can also be built for android.
Get api keys and TVM endpoints:
You need to get an API-KEY here https://dashboard.evercloud.dev
Usage
All requests are async
Errors
Setup TONSDK For Linux and MacOS
Install sdk with bash script
This download SDK to current dirrectory, compile it and add library symlinks to your system
For install or update the SDK version simply by running these command
Manual install sdk ( if you have any problem with script install_tonsdk.sh )
SPOILER: Manual installation
macOS :
./SDK/target/release/libton_client.dylib
to
/usr/local/lib/libton_client.dylib
./SDK/target/release/libton_client.so
to
/usr/lib/libton_client.so
6. Create pkgConfig file :
macOS :
/usr/local/lib/pkgconfig/libton_client.pc
Linux:
/usr/lib/pkgconfig/libton_client.pc
/SDK/ton_client/client/tonclient.h
to
MacOS:
/usr/local/include/tonclient.h
Linux:
/usr/include/tonclient.h
Setup TONSDK For iOS
Go to your project folder and:
⚠️ Wait installation
In xcode File > Add files to “Name Your Project” navigate to ./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:
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
Optional: Install locale NodeSE for tests if you needed:
nodeSE will start on localhost:80
MacOS:
Run Tests inside Xcode
Linux:
swift test –generate-linuxmain
swift test –enable-test-discovery
Update SDK