Skip to content

Commit 460c648

Browse files
authored
Merge pull request #128 from BANKEX/feature/updatingReadme
Feature/updating readme
2 parents 8bbde2e + 8d7a985 commit 460c648

File tree

1 file changed

+116
-14
lines changed

1 file changed

+116
-14
lines changed

README.md

Lines changed: 116 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,37 +70,139 @@ You can try it by yourself by running the example project:
7070
- run `pod install` from the `Example/web3swiftExample` directory.
7171
- `open ./web3swiftExample.xcworkspace`
7272

73-
### Requirements
73+
## Requirements
7474

7575
Web3swift requires Swift 4.1 and iOS 9.0 or macOS 10.13 although we recommend to use the latest iOS and MacOS versions for your own safety. Don't forget to set iOS version in a Podfile, otherwise you get an error if deployment target is less than the latest SDK.
7676

77-
### Installation
77+
## Communication
7878

79-
web3swift is available through [CocoaPods](http://cocoapods.org). To install
80-
it, simply add the following line to your Podfile:
79+
- if you **need help**, use [Stack Overflow](https://stackoverflow.com/questions/tagged/web3swift) (tag 'web3swift')
80+
- If you'd like to **ask a general question**, use [Stack Overflow](http://stackoverflow.com/questions/tagged/web3swift).
81+
- If you **found a bug**, [open an issue](https://github.com/BANKEX/web3swift/issues).
82+
- If you **have a feature request**, [open an issue](https://github.com/BANKEX/web3swift/issues).
83+
- If you **want to contribute**, [submit a pull request](https://github.com/BANKEX/web3swift/pulls).
84+
85+
## Installation
86+
87+
### CocoaPods
88+
89+
[CocoaPods](http://cocoapods.org) is a dependency manager for Cocoa projects. You can install it with the following command:
90+
91+
```bash
92+
$ sudo gem install cocoapods
93+
```
94+
95+
96+
To integrate web3swift into your Xcode project using CocoaPods, specify it in your `Podfile`:
8197

8298
```ruby
83-
pod 'web3swift', git: 'https://github.com/BANKEX/web3swift.git'
99+
source 'https://github.com/CocoaPods/Specs.git'
100+
platform :ios, '9.0'
101+
102+
target '<Your Target Name>' do
103+
use_frameworks!
104+
pod 'web3swift', :git => 'https://github.com/BANKEX/web3swift.git'
105+
end
106+
```
107+
108+
Then, run the following command:
109+
110+
```bash
111+
$ pod install
112+
```
113+
## Features
114+
115+
- [x] Create Account
116+
- [x] Import Account
117+
- [x] Sign transictions
118+
- [x] Send transactions, call functions of smart-contracts, estimate gas costs
119+
- [x] Serialize and deserialize transactions and results to native Swift types
120+
- [x] Convenience functions for chain state: block number, gas price
121+
- [x] Check transaction results and get receipt
122+
- [x] Parse event logs for transaction
123+
- [x] Manage user's private keys through encrypted keystore abstractions
124+
- [x] Batched requests in concurrent mode, checks balances of 580 tokens (from the latest MyEtherWallet repo) over 3 seconds
125+
126+
## Usage
127+
128+
Here you can see a few examples of use of our library
129+
### Initializing Ethereum address
130+
```bash
131+
let coldWalletAddress = EthereumAddress("0x6394b37Cf80A7358b38068f0CA4760ad49983a1B")!
132+
let constractAddress = EthereumAddress("0x45245bc59219eeaaf6cd3f382e078a461ff9de7b")!
84133
```
85-
### Current functionality
86134

87-
- Send transactions, call functions of smart-contracts, estimate gas costs
88-
- Serialize and deserialize transactions and results to native Swift types
89-
- Convenience functions for chain state: block number, gas price
90-
- Check transaction results and get receipt
91-
- Parse event logs for transaction
92-
- Manage user's private keys through encrypted keystore abstractions
93-
- Batched requests in concurrent mode, checks balances of 580 tokens (from the latest MyEtherWallet repo) over 3 seconds
135+
### Getting gas price
136+
```bash
137+
let web3Main = Web3.InfuraMainnetWeb3()
138+
let gasPriceResult = web3Main.eth.getGasPrice()
139+
guard case .success(let gasPrice) = gasPriceResult else {return}
140+
```
141+
### Setting options
142+
```bash
143+
var options = Web3Options.defaultOptions()
144+
options.gasPrice = gasPrice
145+
options.from = EthereumAddress("0xE6877A4d8806e9A9F12eB2e8561EA6c1db19978d")!
146+
let parameters = [] as [AnyObject]
147+
```
148+
149+
### Getting balance
150+
```bash
151+
guard let bkxBalanceResult = contract.method("balanceOf", parameters: [coldWalletAddress] as [AnyObject], options: options)?.call(options: nil) else {return}
152+
guard case .success(let bkxBalance) = bkxBalanceResult, let bal = bkxBalance["0"] as? BigUInt else {return}
153+
print("BKX token balance = " + String(bal))
154+
```
155+
156+
### Sending ETH
157+
```bash
158+
let web3Rinkeby = Web3.InfuraRinkebyWeb3()
159+
160+
web3Rinkeby.addKeystoreManager(bip32keystoreManager)
161+
options.from = bip32ks?.addresses?.first!
162+
intermediateSend = web3Rinkeby.contract(coldWalletABI, at: coldWalletAddress, abiVersion: 2)!.method(options: options)!
163+
let sendResultBip32 = intermediateSend.send(password: "BANKEXFOUNDATION")
164+
switch sendResultBip32 {
165+
case .success(let r):
166+
print(r)
167+
case .failure(let err):
168+
print(err)
169+
}
170+
```
94171
95-
### Global plans
172+
### Sending ERC20
173+
```bash
174+
var convenienceTransferOptions = Web3Options.defaultOptions()
175+
convenienceTransferOptions.gasPrice = gasPriceRinkeby
176+
let convenienceTokenTransfer = web3Rinkeby.eth.sendERC20tokensWithNaturalUnits(tokenAddress: EthereumAddress("0xa407dd0cbc9f9d20cdbd557686625e586c85b20a")!, from: (ks?.addresses?.first!)!, to: EthereumAddress("0x6394b37Cf80A7358b38068f0CA4760ad49983a1B")!, amount: "0.0001", options: convenienceTransferOptions)
177+
let gasEstimateResult2 = convenienceTokenTransfer!.estimateGas(options: nil)
178+
guard case .success(let gasEstimate2) = gasEstimateResult2 else {return}
179+
convenienceTransferOptions.gasLimit = gasEstimate2
180+
let convenienceTransferResult = convenienceTokenTransfer!.send(password: "BANKEXFOUNDATION", options: convenienceTransferOptions)
181+
switch convenienceTransferResult {
182+
case .success(let res):
183+
print("Token transfer successful")
184+
print(res)
185+
case .failure(let error):
186+
print(error)
187+
}
188+
```
189+
190+
## Global plans
96191
- Full reference `web3js` functionality
97192
- Light Ethereum subprotocol (LES) integration
98193
194+
## [Apps using this library](https://github.com/BANKEX/web3swift/wiki/Apps-using-web3swift)
195+
196+
If you've used this project in a live app, please let us know!
197+
198+
*If you are using `web3swift` in your app or know of an app that uses it, please add it to [this] (https://github.com/BANKEX/web3swift/wiki/Apps-using-web3swift) list.*
199+
99200
## Special thanks to
100201
101202
- Gnosis team and their library [Bivrost-swift](https://github.com/gnosis/bivrost-swift) for inspiration for the ABI decoding approach
102203
- [Trust iOS Wallet](https://github.com/TrustWallet/trust-wallet-ios) for collaboration and discussion for initial idea
103204
- Official Ethereum and Solidity docs, everything was written from ground truth standards
205+
104206
## Contribution
105207
106208
For the latest version, please check [develop](https://github.com/BANKEX/web3swift/tree/develop) branch.

0 commit comments

Comments
 (0)