Skip to content

Commit f3507dc

Browse files
authored
Merge pull request #133 from BANKEX/develop
Merge update readme
2 parents 5a60dd5 + 5b7f258 commit f3507dc

File tree

1 file changed

+116
-15
lines changed

1 file changed

+116
-15
lines changed

README.md

Lines changed: 116 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,39 +70,140 @@ 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
78+
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`:
7897

79-
web3swift is available through [CocoaPods](http://cocoapods.org). To install
80-
it, simply add the following line to your `Podfile`:
8198

8299
```ruby
83-
pod 'web3swift', git: 'https://github.com/BANKEX/web3swift.git'
100+
source 'https://github.com/CocoaPods/Specs.git'
101+
platform :ios, '9.0'
102+
103+
target '<Your Target Name>' do
104+
use_frameworks!
105+
pod 'web3swift', :git => 'https://github.com/BANKEX/web3swift.git'
106+
end
107+
```
108+
109+
Then, run the following command:
110+
111+
```bash
112+
$ pod install
113+
```
114+
## Features
115+
116+
- [x] Create Account
117+
- [x] Import Account
118+
- [x] Sign transictions
119+
- [x] Send transactions, call functions of smart-contracts, estimate gas costs
120+
- [x] Serialize and deserialize transactions and results to native Swift types
121+
- [x] Convenience functions for chain state: block number, gas price
122+
- [x] Check transaction results and get receipt
123+
- [x] Parse event logs for transaction
124+
- [x] Manage user's private keys through encrypted keystore abstractions
125+
- [x] Batched requests in concurrent mode, checks balances of 580 tokens (from the latest MyEtherWallet repo) over 3 seconds
126+
127+
## Usage
128+
129+
Here you can see a few examples of use of our library
130+
### Initializing Ethereum address
131+
```bash
132+
let coldWalletAddress = EthereumAddress("0x6394b37Cf80A7358b38068f0CA4760ad49983a1B")!
133+
let constractAddress = EthereumAddress("0x45245bc59219eeaaf6cd3f382e078a461ff9de7b")!
134+
```
135+
136+
### Getting gas price
137+
```bash
138+
let web3Main = Web3.InfuraMainnetWeb3()
139+
let gasPriceResult = web3Main.eth.getGasPrice()
140+
guard case .success(let gasPrice) = gasPriceResult else {return}
141+
```
142+
### Setting options
143+
```bash
144+
var options = Web3Options.defaultOptions()
145+
options.gasPrice = gasPrice
146+
options.from = EthereumAddress("0xE6877A4d8806e9A9F12eB2e8561EA6c1db19978d")!
147+
let parameters = [] as [AnyObject]
148+
```
149+
150+
### Getting balance
151+
```bash
152+
guard let bkxBalanceResult = contract.method("balanceOf", parameters: [coldWalletAddress] as [AnyObject], options: options)?.call(options: nil) else {return}
153+
guard case .success(let bkxBalance) = bkxBalanceResult, let bal = bkxBalance["0"] as? BigUInt else {return}
154+
print("BKX token balance = " + String(bal))
84155
```
85156
86-
Run `pod install` from the command line
87-
### Current functionality
157+
### Sending ETH
158+
```bash
159+
let web3Rinkeby = Web3.InfuraRinkebyWeb3()
160+
161+
web3Rinkeby.addKeystoreManager(bip32keystoreManager)
162+
options.from = bip32ks?.addresses?.first!
163+
intermediateSend = web3Rinkeby.contract(coldWalletABI, at: coldWalletAddress, abiVersion: 2)!.method(options: options)!
164+
let sendResultBip32 = intermediateSend.send(password: "BANKEXFOUNDATION")
165+
switch sendResultBip32 {
166+
case .success(let r):
167+
print(r)
168+
case .failure(let err):
169+
print(err)
170+
}
171+
```
88172
89-
- Send transactions, call functions of smart-contracts, estimate gas costs
90-
- Serialize and deserialize transactions and results to native Swift types
91-
- Convenience functions for chain state: block number, gas price
92-
- Check transaction results and get receipt
93-
- Parse event logs for transaction
94-
- Manage user's private keys through encrypted keystore abstractions
95-
- Batched requests in concurrent mode, checks balances of 580 tokens (from the latest MyEtherWallet repo) over 3 seconds
173+
### Sending ERC20
174+
```bash
175+
var convenienceTransferOptions = Web3Options.defaultOptions()
176+
convenienceTransferOptions.gasPrice = gasPriceRinkeby
177+
let convenienceTokenTransfer = web3Rinkeby.eth.sendERC20tokensWithNaturalUnits(tokenAddress: EthereumAddress("0xa407dd0cbc9f9d20cdbd557686625e586c85b20a")!, from: (ks?.addresses?.first!)!, to: EthereumAddress("0x6394b37Cf80A7358b38068f0CA4760ad49983a1B")!, amount: "0.0001", options: convenienceTransferOptions)
178+
let gasEstimateResult2 = convenienceTokenTransfer!.estimateGas(options: nil)
179+
guard case .success(let gasEstimate2) = gasEstimateResult2 else {return}
180+
convenienceTransferOptions.gasLimit = gasEstimate2
181+
let convenienceTransferResult = convenienceTokenTransfer!.send(password: "BANKEXFOUNDATION", options: convenienceTransferOptions)
182+
switch convenienceTransferResult {
183+
case .success(let res):
184+
print("Token transfer successful")
185+
print(res)
186+
case .failure(let error):
187+
print(error)
188+
}
189+
```
96190
97-
### Global plans
191+
## Global plans
98192
- Full reference `web3js` functionality
99193
- Light Ethereum subprotocol (LES) integration
100194
195+
## [Apps using this library](https://github.com/BANKEX/web3swift/wiki/Apps-using-web3swift)
196+
197+
If you've used this project in a live app, please let us know!
198+
199+
*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.*
200+
101201
## Special thanks to
102202
103203
- Gnosis team and their library [Bivrost-swift](https://github.com/gnosis/bivrost-swift) for inspiration for the ABI decoding approach
104204
- [Trust iOS Wallet](https://github.com/TrustWallet/trust-wallet-ios) for collaboration and discussion for initial idea
105205
- Official Ethereum and Solidity docs, everything was written from ground truth standards
206+
106207
## Contribution
107208
108209
For the latest version, please check [develop](https://github.com/BANKEX/web3swift/tree/develop) branch.

0 commit comments

Comments
 (0)