All Projects → horizontalsystems → ethereum-kit-ios

horizontalsystems / ethereum-kit-ios

Licence: MIT license
Comprehensive EVM SDK (ex: Ethereum, Binance Smart Chain) for iOS, implemented on Swift. Create wallets, watch wallets (read-only), sync transactions, filter transactions by type (erc20, bep20, swap transactions etc.), swap using native DEX protocols, easily extendable to work with custom smart contracts, and full support for EIP1159.

Programming Languages

swift
15916 projects
c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to ethereum-kit-ios

Android-Wallet-Token-ERC20
Android Wallet (Token ERC20)
Stars: ✭ 30 (-79.73%)
Mutual labels:  ethereum-client, ethereum-wallet, erc20-tokens, ethereum-tokens
Wallet3
A secure mobile wallet for web3
Stars: ✭ 13 (-91.22%)
Mutual labels:  web3, erc20, erc721, erc1155
niftygate
Drop-in Access Control via NFT Ownership
Stars: ✭ 61 (-58.78%)
Mutual labels:  web3, erc20, erc721, erc1155
nft-swap-sdk
Ethereum's missing p2p NFT and token swap library for web3 developers. Written in TypeScript. Powered by 0x.
Stars: ✭ 200 (+35.14%)
Mutual labels:  web3, erc20, erc721, erc1155
defi-dapps-solidity-smart-contracts
This is a Web 3 Smart Contract learning and teaching repo which will be used to teach students all across Pakistan.
Stars: ✭ 241 (+62.84%)
Mutual labels:  erc20, erc721, erc1155
Smart-Contract-Security-Audits
Certified Smart Contract Audits (Ethereum, Hyperledger, xDAI, Huobi ECO Chain, Binance Smart Chain, Fantom, EOS, Tezos) by Chainsulting
Stars: ✭ 325 (+119.59%)
Mutual labels:  erc20-tokens, binance-smart-chain, bep20
cryptowallet-cli
CW is a crypto wallet generator CLI tool for a lot of blockchains: Bitcoin, Ethereum, Binance Smart Chain and many others
Stars: ✭ 45 (-69.59%)
Mutual labels:  erc20, binance-smart-chain, bep20
Artion-Server
Artion API Server
Stars: ✭ 26 (-82.43%)
Mutual labels:  web3, erc721, erc1155
Cryptocurrency Icons
A set of icons for all the main cryptocurrencies and altcoins, in a range of styles and sizes.
Stars: ✭ 2,116 (+1329.73%)
Mutual labels:  erc20, erc20-tokens, erc721
desktop
CoinApp is a simple to use minimal Cryptocurrency Wallet for Ethereum, ERC20 Tokens, Bitcoin and Litecoin built for Windows, Mac and Linux.
Stars: ✭ 60 (-59.46%)
Mutual labels:  ethereum-wallet, erc20, erc20-tokens
uniswap-arbitrage-flash-swap
Uniswap flash swap arbitrage solidity contracts
Stars: ✭ 341 (+130.41%)
Mutual labels:  bsc, web3, binance-smart-chain
starkgate-frontend
Bridge interface allows users to transfer ERC20 tokens from Ethereum to StarkNet and vice versa.
Stars: ✭ 75 (-49.32%)
Mutual labels:  erc20, erc20-tokens
storj-wallet
Storj Wallet for Windows, Mac and Linux. Send and Receive Storj ERC20 Token and Ethereum (unofficial)
Stars: ✭ 13 (-91.22%)
Mutual labels:  erc20, ethereum-dapp
ethereum-erc20
Fungible token implementation for the Ethereum blockchain.
Stars: ✭ 27 (-81.76%)
Mutual labels:  erc20, erc-20
vue-web3
🐙 Web3 blockchain bindings for Vue.js (inspired by Vuefire and Drizzle)
Stars: ✭ 63 (-57.43%)
Mutual labels:  web3, ethereum-dapp
ethereum-crowdsale
0xcert protocol crowdsale contracts for Ethereum blockchain.
Stars: ✭ 15 (-89.86%)
Mutual labels:  erc20, erc-20
botdexdamar
🤖 multichain trading bot with sniper, frontrun, backrun, sandwich
Stars: ✭ 124 (-16.22%)
Mutual labels:  bsc, web3
coinmarketcap-ethtoken-db
A database of Ethereum tokens on CoinMarketCap.com in machine-friendly format
Stars: ✭ 25 (-83.11%)
Mutual labels:  erc20, ethereum-tokens
Rabby
The game-changing wallet for Ethereum and all EVM chains
Stars: ✭ 562 (+279.73%)
Mutual labels:  bsc, ethereum-wallet
NFT-Dapp-Boilerplate
A highly scalable NFT and DEFI boilerplate with pre added web3 and different wallets with a focus on performance and best practices
Stars: ✭ 51 (-65.54%)
Mutual labels:  web3, ethereum-dapp

EthereumKit-iOS

EthereumKit-iOS is a native(Swift), secure, reactive and extensible Ethereum client toolkit for iOS platform. It can be used by ETH/Erc20 wallet or by dapp client for any kind of interactions with Ethereum blockchain.

Features

  • Ethereum wallet support, including internal Ether transfer transactions
  • Support for ERC20 token standard
  • Uniswap DEX support
  • Reactive-functional API
  • Implementation of Ethereum's JSON-RPC client API over HTTP or WebSocket
  • Support for Infura
  • Support for Etherscan

EthereumKit.swift

  • Sync account state/balance
  • Sync/Send/Receive Ethereum transactions
  • Internal transactions retrieved from Etherscan
  • Reactive API for Smart Contracts (Erc20Kit.swift and UniswapKit.swift use EthereumKit.swift for interactions with the blockchain)
  • Reactive API for wallet
  • Restore with mnemonic phrase

Erc20Kit.swift

  • Sync balance
  • Sync/Send/Receive Erc20 token transactions
  • Allowance management
  • Incoming Erc20 token transactions retrieved from Etherscan
  • Reactive API for wallet

UniswapKit.swift

Supports following settings:

  • Price Impact
  • Deadline
  • Recipient
  • Fee on Transfer

Usage

Initialization

First you need to initialize an EthereumKit.Kit instance

import EthereumKit

let ethereumKit = try! Kit.instance(
        words: ["word1", ... , "word12"],
        syncMode: .api,
        networkType: .ropsten,
        rpcApi: .infuraWebSocket(id: "", secret: ""),
        etherscanApiKey: "",
        walletId: "walletId",
        minLogLevel: .error
)
syncMode parameter
  • .api: Uses RPC
  • .spv: Ethereum light client. Not supported currently
  • .geth: Geth client. Not supported currently
networkfkType parameter
  • .mainNet
  • .ropsten
  • .kovan
rpcApi parameter
  • .infuraWebSocket(id: "", secret: ""): RPC over HTTP
  • .infura(id: "", secret: """): RPC over WebSocket
Additional parameters:
  • minLogLevel: Can be configured for debug purposes if required.

Starting and Stopping

EthereumKit.Kit instance requires to be started with start command

ethereumKit.start()
ethereumKit.stop()

Getting wallet data

You can get account state, lastBlockHeight, syncState, transactionsSyncState and some others synchronously

guard let state = ethereumKit.accountState else {
    return
}

state.balance    // 2937096768
state.nonce      // 10

ethereumKit.lastBlockHeight  // 10000000

You also can subscribe to Rx observables of those and some others

ethereumKit.accountStateObservable.subscribe(onNext: { state in print("balance: \(state.balance); nonce: \(state.nonce)") })
ethereumKit.lastBlockHeightObservable.subscribe(onNext: { height in print(height) })
ethereumKit.syncStateObservable.subscribe(onNext: { state in print(state) })
ethereumKit.transactionsSyncStateObservable.subscribe(onNext: { state in print(state) })

// Subscribe to all Ethereum transactions synced by the kit
ethereumKit.allTransactionsObservable.subscribe(onNext: { transactions in print(transactions.count) })

// Subscribe to Ether transactions
ethereumKit.etherTransactionsObservable.subscribe(onNext: { transactions in print(transactions.count) })

Send Transaction

let decimalAmount: Decimal = 0.1
let amount = BigUInt(decimalAmount.roundedString(decimal: decimal))!
let address = Address(hex: "0x73eb56f175916bd17b97379c1fdb5af1b6a82c84")!

ethereumKit
        .sendSingle(address: address, value: amount, gasPrice: 50_000_000_000, gasLimit: 1_000_000_000_000)
        .subscribe(onSuccess: { transaction in 
            print(transaction.transaction.hash.hex)  // sendSingle returns FullTransaction object which contains transaction, receiptWithLogs and internalTransactions
        })

Estimate Gas Limit

let decimalAmount: Decimal = 0.1
let amount = BigUInt(decimalAmount.roundedString(decimal: decimal))!
let address = Address(hex: "0x73eb56f175916bd17b97379c1fdb5af1b6a82c84")!

ethereumKit
        .estimateGas(to: address, amount: amount, gasPrice: 50_000_000_000)
        .subscribe(onSuccess: { gasLimit in 
            print(gasLimit)
        })

Send Erc20 Transaction

import EthereumKit
import Erc20Kit

let decimalAmount: Decimal = 0.1
let amount = BigUInt(decimalAmount.roundedString(decimal: decimal))!
let address = Address(hex: "0x73eb56f175916bd17b97379c1fdb5af1b6a82c84")!

let erc20Kit = Erc20Kit.Kit.instance(ethereumKit: ethereumKit, contractAddress: "contract address of token")
let transactionData = erc20Kit.transferTransactionData(to: address, value: amount)

ethereumKit
        .sendSingle(transactionData: transactionData, gasPrice: 50_000_000_000, gasLimit: 1_000_000_000_000)
        .subscribe(onSuccess: { [weak self] _ in})

Send Uniswap swap transaction

import EthereumKit
import UniswapKit
import Erc20Kit

let uniswapKit = UniswapKit.Kit.instance(ethereumKit: ethereumKit)

let tokenIn = uniswapKit.etherToken
let tokenOut = uniswapKit.token(try! Address(hex: "0xad6d458402f60fd3bd25163575031acdce07538d"), decimal: 18)
let amount: Decimal = 0.1

uniswapKit
        .swapDataSingle(tokenIn: tokenIn, tokenOut: tokenOut)
        .flatMap { swapData in
            let tradeData = try! uniswapKit.bestTradeExactIn(swapData: swapData, amountIn: amount)
            let transactionData = try! uniswapKit.transactionData(tradeData: tradeData)
            
            return ethereumKit.sendSingle(transactionData: transactionData, gasPrice: 50_000_000_000, gasLimit: 1_000_000_000_000)
        }
        .subscribe(onSuccess: { [weak self] _ in})

Extending

Add transaction syncer

Some smart contracts store some information concerning your address, which you can't retrieve in a standard way over RPC. If you have an external API to get them from, you can create a custom syncer and add it to EthereumKit. It will sync all the transactions your syncer gives.

Erc20TransactionSyncer is a good example of this. It gets token transfer transactions from Etherscan and feeds EthereumKit syncer with them. It is added to EthereumKit as following:

let transactionSyncer = Erc20TransactionSyncer(...)
ethereumKit.add(syncer: transactionSyncer)

Smart contract call

In order to make a call to any smart contract, you can use ethereumKit.sendSingle(transactionData:,gasPrice:,gasLimit:) method. You need to create an instance of TransactionData object. Currently, we don't have an ABI or source code parser. Please, look in Erc20Kit.swift and UniswapKit.swift to see how TransactionData object is formed.

Prerequisites

  • Xcode 10.0+
  • Swift 5+
  • iOS 11+

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

CocoaPods 1.5.0+ is required to build EthereumKit.

To integrate EthereumKit into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

target '<Your Target Name>' do
  pod 'EthereumKit.swift'
  pod 'Erc20.swift'
  pod 'UniswapKit.swift'
end

Then, run the following command:

$ pod install

Example Project

All features of the library are used in example project. It can be referred as a starting point for usage of the library.

Dependencies

  • HSHDWalletKit - HD Wallet related features, mnemonic phrase generation.
  • OpenSslKit.swift - Crypto functions required for working with blockchain.
  • Secp256k1Kit.swift - Crypto functions required for working with blockchain.
  • HsToolKit.swift - Helpers library from HorizontalSystems
  • RxSwift
  • BigInt
  • GRDB.swift
  • Starscream

License

The EthereumKit-iOS toolkit is open source and available under the terms of the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].