Coder Social home page Coder Social logo

nerzh / everscale-client-swift Goto Github PK

View Code? Open in Web Editor NEW
18.0 3.0 6.0 756 KB

Swift Binding for Everscale, Venom SDK. Library for interacting with Everscale, Venom blockchain.

License: GNU General Public License v3.0

Swift 96.86% C 0.01% Shell 0.72% Solidity 2.41%
swift ton-client everscale everscale-sdk everscale-client ios linux macos venom-blockchain venom-sdk venom-tools

everscale-client-swift's Introduction

Swift Client for TVM SDK (everscale, venom, gosh)

SPM SPM

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.

OS Result
MacOS
Linux
iOS
Windows Soon

Get api keys and TVM endpoints:

You need to get an API-KEY here https://dashboard.evercloud.dev

Usage

All requests are async

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

  1. This download SDK to current dirrectory, compile it and add library symlinks to your system
cd everscale-client-swift
  1. 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 )

SPOILER: Manual installation
  1. Install Rust to your OS

  2. git clone https://github.com/tonlabs/ever-sdk

  3. cd ./SDK

  4. cargo update

  5. cargo build --release

  6. copy or create symlink of dynamic library
    macOS :
    ./SDK/target/release/libton_client.dylib
    to
    /usr/local/lib/libton_client.dylib

    Linux :
    ./SDK/target/release/libton_client.so
    to
    /usr/lib/libton_client.so

  7. Create pkgConfig file :

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
  1. Copy or create symlink of file
    /SDK/ton_client/client/tonclient.h
    to
    MacOS:
    /usr/local/include/tonclient.h
    Linux:
    /usr/include/tonclient.h

Setup TONSDK For iOS

  1. Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh || true && \
source ~/.profile
  1. Install "cargo lipo"
rustup target add aarch64-apple-ios x86_64-apple-ios || true && \
cargo install cargo-lipo
  1. Build SDK for iOS

Go to your project folder and:

git clone https://github.com/tonlabs/SDK.git || true && \
cd ./SDK
git pull --ff-only || true && \
cargo update || true && \
cargo lipo --release

⚠️ Wait installation

  1. In xcode File > Add files to "Name Your Project" navigate to ./SDK/ton_client/tonclient.h

  2. 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:

#ifndef Tonclient_Bridging_Header_h
#define Tonclient_Bridging_Header_h

#include <stdbool.h>
#import "tonclient.h"

#endif
  1. Add path to Tonclient-Bridging-Header.h $(PROJECT_DIR)/Tonclient-Bridging-Header.h

  1. Add path to search for libraries ( path to directory withlibton_client.a ) $(PROJECT_DIR)/SDK/target/universal/release

  1. File > Swift Packages > Add Package Dependency https://github.com/nerzh/ton-client-swift

  1. 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

  1. inside root directory of everscale-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
  1. Run Tests
    MacOS:
    Run Tests inside Xcode
    Linux:
    swift test --generate-linuxmain
    swift test --enable-test-discovery

Update SDK

cd everscale-client-swift
bash api_generate.sh

everscale-client-swift's People

Contributors

nerzh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.