Skip to content
Tesseract dApps Platform SDK for iOS and OSX
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
Sources/Tesseract
Tesseract.xcodeproj
Tests/TesseractTests
.gitignore
.swift-version
.travis.yml
Cartfile
Cartfile.resolved
LICENSE
README.md
TesseractSDK.podspec

README.md

Tesseract.swift Logo

Tesseract dApps Platform SDK for Swift

GitHub license Build Status GitHub release CocoaPods version Platform iOS

Getting started

To use this library compatible wallet should be installed on the device.

We released our own Tesseract Wallet as reference wallet implementation. Install it on your device to check provided examples.

Installation

Add the following to your Podfile:

pod 'TesseractSDK/Ethereum'

Then run pod install.

Hello Tesseract, hello Web3.

Let's try to get Ethereum account balance.

import Tesseract

// Check that we have wallet installed. You should handle this situation in your app.
guard Tesseract.Ethereum.isKeychainInstalled else {
    fatalError("Wallet is not installed!")
}

// Our HTTP RPC URL. Can be Infura
let rpcUrl = "https://mainnet.infura.io/v3/{API-KEY}"

// Creating Web3 instance. Try to reuse existing instance of Web3 in your app.
let web3 = Tesseract.Ethereum.Web3(rpcUrl: rpcUrl)

// Asking wallet for the Account
web3.eth.accounts() { response in
    // Check that we have response
    guard let accounts = response.result else {
        print("Error:", response.error!)
        return
    }
    // Asking network for balance
    web3.eth.getBalance(address: accounts[0]) { response in
        switch response.status {
        case .success(let balance): print("Balance:", balance)
        case .failure(let err): print("Error:", err)
        }
    }
}

With PromiseKit

Install PromiseKit Extensions

Add the following to your Podfile:

pod 'TesseractSDK/Ethereum.PromiseKit'

Then run pod install.

Now you can Web3 like this

import PromiseKit

// Asking wallet for Account
web3.eth.accounts()
    .then { accounts in
        // Obtaining balance
        web3.eth.getBalance(address: accounts[0])
    }.done { balance in
        print("Balance:", balance)
    }.catch { err in
        print("Error:", err)
    }

Examples

New transaction

// Creating Transaction
let tx = Transaction(
    from: account, // Account from previous examples
    to: try! Address(hex: "0x..."),
    value: 1.eth
)

// Sending it. Tesseract will handle signing automatically.
web3.eth.sendTransaction(transaction: tx) { response in
    switch response.status {
    case .success(let hash): print("TX Hash:", hash.hex())
    case .failure(let err): print("Error:", err)
    }
}

PromiseKit

// Sending it. Tesseract will handle signing automatically.
web3.eth.sendTransaction(transaction: tx)
    .done { hash in
        print("TX Hash:", hash.hex())
    }.catch { err in
        print("Error:", err)
    }

ERC20 Smart Contract

Create Smart Contract instance

// EOS ERC20 token
let contractAddress = try! Address(hex: "0x86Fa049857E0209aa7D9e616F7eb3b3B78ECfdb0")
// ERC20 contract object
let contract = web3.eth.Contract(type: GenericERC20Contract.self, address: contractAddress)

Get ERC20 balance

contract.balanceOf(address: account) // Account from previous steps
    .call() // Performing Ethereum Call
    .done { outputs in
        print("Balance:", outputs["_balance"] as! BigUInt)
    }.catch { error in
        print("Error:", error)
    }

Send ERC20 tokens

// Our recipient
let recipient = try! Address(hex: "0x....")

contract
    .transfer(to: recipient, value: 100000) // Creating SC invocaion
    .send(from: account) // Sending it from our account
    .done { hash in
        print("TX Hash:", hash.hex())
    }.catch { err in
        print("Error:", err)
    }

Custom Smart Contract

Web3 can parse you JSON smart contract ABI.

You can use methods of Smart Contract by subcripting them by name from the Contract object.

Create Smart Contract instance

// EOS ERC20 token
let contractAddress = try! Address(hex: "0x86Fa049857E0209aa7D9e616F7eb3b3B78ECfdb0")
// JSON ABI. Can be loaded from json file
let contractJsonABI = "<your contract ABI as a JSON string>".data(using: .utf8)!
// You can optionally pass an abiKey param if the actual abi is nested and not the top level element of the json
let contract = try web3.eth.Contract(json: contractJsonABI, abiKey: nil, address: contractAddress)

Get ERC20 balance

contract["balanceOf"]!(account) // Account from previous steps
    .call()
    .done { outputs in
        print("Balance:", outputs["_balance"] as! BigUInt)
    }.catch { error in
        print("Error:", error)
    }

Send ERC20 tokens

// Our recipient
let recipient = try! Address(hex: "0x....")

// Creating ERC20 call object
let invocation = contract["transfer"]!(recipient, BigUInt(100000))

invocation
    .send(from: account) // Sending it from our account
    .done { hash in
        print("TX Hash:", hash.hex())
    }.catch { err in
        print("Error:", err)
    }

More Examples

For more examples check Web3.swift library used inside.

SDK Structure

This SDK has modular structure. All modules can be installed with CocoaPods.

Right now SDK has this modules:

Modules installation

Modules can be installed one-by-one.

As example, if you want to install Web3 only add the following to your Podfile:

pod 'TesseractSDK/Ethereum.Web3'

# Uncomment this line if you want to enable Web3 PromiseKit extensions
# pod 'TesseractSDK/Ethereum.Web3.PromiseKit'

Then run pod install.

Ideology behind

Tesseract dApps Platform emerged from one simple vision - dApps should not store Private Keys inside.

With this vision we created Mobile-first platform. It allows app developers to write Native dApps and leave all key storage security tasks to Wallet developers.

We started with open protocol, which describes Wallet <-> dApp communication. It's called Open Wallet.

This SDK can interact with any Wallet which implemented this protocol. Ask your preferred Wallet to implement it :)

Author

License

Tesseract.swift is available under the Apache 2.0 license. See the LICENSE file for more information.

You can’t perform that action at this time.