Skip to content
Web3 and Geth wrapper utility in swift
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Source Update Geth Pod Mar 8, 2018
Tests Merge branch 'master' of github.com:MercuryProtocol/web3.swift Feb 5, 2018
web3swift.xcodeproj update documentation Feb 2, 2018
web3swift.xcworkspace Initial commit Feb 2, 2018
.gitignore Initial commit Feb 2, 2018
CHANGELOG.md Update Geth Pod Mar 8, 2018
CONTRIBUTING.md Initial commit Feb 2, 2018
LICENSE Update LICENSE Feb 2, 2018
Podfile Update Geth Pod Mar 8, 2018
Podfile.lock Update Geth Pod Mar 8, 2018
README.md Update Tag Mar 8, 2018
web3swift.podspec Update web3swift.podspec Mar 8, 2018

README.md

CocoaPods Compatible Platform Latest Tag Twitter

web3.js utility library written in Swift.

Table of contents

Features

  • Create Account
  • Import Account
  • Create and Encode Transaction
  • Sign Transaction
  • More Features - WIP
  • Complete Documentation

Component Libraries

In order to keep web3swift focused specifically on core ethereum based utility functionality, additional component libraries will be created by the Radical App LLC to bring additional functionality to the mercury protocol ecosystem.

  • iOS Example App - Example showcasing use of web3swift library.
  • [Mercury Wallet - Wallet App to use with mercury protocol. (Coming Soon)

Requirements

  • iOS 9.0+
  • Xcode 9.2+
  • Swift 4.0.0+

Communication

  • If you need help, use Stack Overflow. (Tag 'web3swift')
  • If you'd like to ask a general question, use Stack Overflow.
  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.

Installation

CocoaPods

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

$ sudo gem install cocoapods

CocoaPods 1.1+ is required to build web3swift 4.0+.

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

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'

target '<Your Target Name>' do
    use_frameworks!
    pod 'web3swift', :git => 'https://github.com/MercuryProtocol/web3.swift.git', :branch => 'master'
end

Then, run the following command:

$ pod install

Sidenote:

  • In order to run project, you will have to turn off bitcode support as Geth doesn't support bitcode. Please check: https://github.com/golang/go/issues/22395
  • iOS simulator compilation can be fixed by removing arm7 support from valid architectures in the app. You can find more information here.

USAGE

Create Account

Create keystore and account with password.

let configuration = EthAccountConfiguration(namespace: "wallet", password: "qwerty")
let (keystore, _) = EthAccountCoordinator.default.launch(configuration)

If you don't want to create account, this can be achieved by passing nil

let configuration = EthAccountConfiguration(namespace: "wallet", password: nil)
let (keystore, _) = EthAccountCoordinator.default.launch(configuration)

Encoding Transaction

var addressError: NSError? = nil
let amountToTransfer = 5
let gethToAccountAddress: GethAddress! = GethNewAddressFromHex("0x39db95b4f60bd75846c46df165d9e854b3cf2b56", &addressError)
guard let amount = GethBigInt.bigInt(amountToTransfer) else {
    print("Invalid amount")
    return
}
let transferFunction = EthFunction(name: "transfer", inputParameters: [toAccountAddress, amount])
let encodedTransferFunction = web3swift.encode(transferFunction)

Signing Transaction

let signedTransaction = web3swift.sign(address: contractAddress, encodedFunctionData: encodedTransferFunction, nonce: nonce, gasLimit: Constants.gasLimit, gasPrice: Constants.gasPrice)

FAQ

What's web3swift?

web3swift is utility library written in swift which brings web3j encoding capabilities to Swift. Also, helps managements of account based on Geth.

Credits

web3swift is owned and maintained by the Radical App LLC. You can follow them on Twitter at @MercuryProtocol for project updates and releases.

Contributors

If you do want to participate please follow the guideline.

Security Disclosure

If you believe you have identified a security vulnerability with web3swift, you should report it as soon as possible via email to security@mercuryprotocol.com. Please do not post it to a public issue tracker.

License

web3swift is released under the MIT license. See LICENSE for details.

You can’t perform that action at this time.