Skip to content

Commit e0d3bf6

Browse files
Update README.md
1 parent cf0e358 commit e0d3bf6

File tree

1 file changed

+80
-252
lines changed

1 file changed

+80
-252
lines changed

README.md

Lines changed: 80 additions & 252 deletions
Original file line numberDiff line numberDiff line change
@@ -11,90 +11,71 @@ The work for 2.0 release is about to start. Ideas for new more Swift idiomatic A
1111

1212
**web3swift** is your toolbelt for any kind interactions with Ethereum network.
1313

14-
15-
- [web3swift](#web3swift)
16-
+ [Features:](#features-)
17-
* [Design decisions](#design-decisions)
18-
* [Example](#example)
19-
* [Installation](#installation)
20-
+ [Requirements](#requirements)
21-
+ [CocoaPods](#cocoapods)
22-
* [Getting started](#getting-started)
23-
+ [Create Account](#create-account)
24-
+ [Save keystore to the memory](#save-keystore-to-the-memory)
25-
+ [Initializing Ethereum address](#initializing-ethereum-address)
26-
+ [Setting options](#setting-options)
27-
+ [Encoding Transaction](#encoding-transaction)
28-
+ [Signing Transaction](#signing-transaction)
29-
+ [Getting ETH balance](#getting-eth-balance)
30-
+ [Getting gas price](#getting-gas-price)
31-
+ [Sending ETH](#sending-eth)
32-
+ [ERC20 Iteraction:](#erc20-iteraction-)
33-
- [Getting ERC20 token balance](#getting-erc20-token-balance)
34-
- [Sending ERC20](#sending-erc20)
35-
* [Apps using this library](#apps-using-this-library)
36-
* [Future plans](#future-plans)
37-
+ [Extra features:](#extra-features-)
38-
* [Stay in touch](#stay-in-touch)
39-
+ [Contribution](#contribution)
40-
+ [Communication](#communication)
41-
+ [Special thanks to](#special-thanks-to)
42-
* [Authors](#authors)
43-
* [License](#license)
44-
45-
46-
### Features:
47-
48-
- Swift implementation of [web3.js](https://github.com/ethereum/web3.js/) functionality :zap:
49-
- Interaction with remote node via JSON RPC :thought_balloon:
50-
- Smart-contract ABI parsing :book:
51-
- ABI deconding (V2 is supported with return of structures from public functions. Part of 0.4.22 Solidity compiler)
52-
- RLP encoding
53-
- Interactions (read/write to Smart contracts) :arrows_counterclockwise:
54-
- Local keystore management (`geth` compatible)
55-
- Literally following the standards:
56-
- [BIP32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki) HD Wallets: Deterministic Wallet
57-
- [BIP39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) (Seed phrases)
58-
- [BIP44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki) (Key generation prefixes)
59-
- [EIP-155](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md) (Replay attacks protection) *enforced!*
60-
61-
**Account Managment:**
62-
- [x] Create Account
63-
- [x] Import Account
64-
- [x] Manage user's private keys through encrypted keystore abstractions
65-
66-
**Transactions operations:**
67-
- [x] Sign transactions
68-
- [x] Send transactions, call functions of smart-contracts, estimate gas costs
69-
- [x] Serialize and deserialize transactions and results to native Swift types
70-
- [x] Check transaction results and get the receipt
71-
- [x] Parse event logs for the transaction
72-
- [x] Convenience functions for chain state: block number, gas price
73-
- [x] Batched requests in concurrent mode, check balances of 580 tokens (from the latest MyEtherWallet repo) over 3 seconds
74-
75-
76-
## Design decisions
14+
- [Features](#features)
15+
- [Design Decisions](#design-decisions)
16+
- [Requirements](#requirements)
17+
- [Migration Guides](#migration-guides)
18+
- [Communication](#communication)
19+
- [Installation](#installation)
20+
- [Usage](https://github.com/matterinc/web3swift/blob/master/Documentation/Usage.md)
21+
- **Account Management -** [Create Account](https://github.com/matterinc/web3swift/blob/master/Documentation/Usage.md#create-account), [Import Account](https://github.com/matterinc/web3swift/blob/master/Documentation/Usage.md#import-account), [Manage Keystore](https://github.com/matterinc/web3swift/blob/master/Documentation/Usage.md#manage-keystore), [Ethereum Address](https://github.com/matterinc/web3swift/blob/master/Documentation/Usage.md#ethereum-address), [Get Balance](https://github.com/matterinc/web3swift/blob/master/Documentation/Usage.md#get-balance)
22+
- **Transactions Operations -** [Prepare Transaction](https://github.com/matterinc/web3swift/blob/master/Documentation/Usage.md#prepare-transaction), [Send Transaction](https://github.com/matterinc/web3swift/blob/master/Documentation/Usage.md#send-transaction), [Get gas price](https://github.com/matterinc/web3swift/blob/master/Documentation/Usage.md#transaction-gasprice), [Serialize & deserialize transactions](https://github.com/matterinc/web3swift/blob/master/Documentation/Usage.md#serialize-deserialize-transactions), [Get result](https://github.com/matterinc/web3swift/blob/master/Documentation/Usage.md#get-result)
23+
- **Chain State -** [Get Block number](https://github.com/matterinc/web3swift/blob/master/Documentation/Usage.md#get-block-number), [Get gas price](https://github.com/matterinc/web3swift/blob/master/Documentation/Usage.md#block-gasprice)
24+
- [Example Project](#example-project)
25+
- [Credits](#credits)
26+
- [Donations](#donations)
27+
- [License](#license)
28+
29+
## Features
30+
31+
- [x] Swift implementation of [web3.js](https://github.com/ethereum/web3.js/) functionality :zap:
32+
- [x] Interaction with remote node via JSON RPC :thought_balloon:
33+
- [x] Smart-contract ABI parsing :book:
34+
- [x] ABI deconding (V2 is supported with return of structures from public functions. Part of 0.4.22 Solidity compiler)
35+
- [x] RLP encoding
36+
- [x] Interactions (read/write to Smart contracts) :arrows_counterclockwise:
37+
- [x] Local keystore management (`geth` compatible)
38+
- [x] Batched requests in concurrent mode
39+
- [x] Literally following the standards:
40+
- [x] [BIP32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki) HD Wallets: Deterministic Wallet
41+
- [x] [BIP39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) (Seed phrases)
42+
- [x] [BIP44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki) (Key generation prefixes)
43+
- [x] [EIP-155](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md) (Replay attacks protection) *enforced!*
44+
- [x] Comprehensive Unit and Integration Test Coverage
45+
- [x] [Complete Documentation](https://web3swift.github.io/web3swift)
46+
47+
## Design Desisions
7748

7849
- Not every JSON RPC function is exposed yet, and priority is given to the ones required for mobile devices
7950
- Functionality was focused on serializing and signing transactions locally on the device to send raw transactions to Ethereum network
8051
- Requirements for password input on every transaction are indeed a design decision. Interface designers can save user passwords with the user's consent
8152
- Public function for private key export is exposed for user convenience but marked as UNSAFE_ :) Normal workflow takes care of EIP155 compatibility and proper clearing of private key data from memory
8253

83-
## Example
54+
## Requirements
8455

85-
You can try it yourself by running the example project:
56+
- iOS 9.0+ / macOS 10.11+
57+
- Xcode 9.0+
58+
- Swift 4.1+
8659

87-
- Clone the repo: `git clone https://github.com/matterinc/web3swift.git`
88-
- Move to the repo: `cd web3swift/Example/web3swiftExample`
89-
- Install Dependencies: `pod install`
90-
- Open: `open ./web3swiftExample.xcworkspace`
60+
## Migration Guides
9161

62+
- [web3swift 2.0 Migration Guide](https://github.com/matterinc/web3swift/blob/master/Documentation/web3swift%202.0%20Migration%20Guide.md)
9263

93-
## Installation
64+
## Communication
9465

95-
### Requirements
66+
When using this lib, please make references to this repo and give your start! :)
67+
*Nothing makes developers happier than seeing someone else use our work and go wild with it.*
9668

97-
Web3swift requires `Swift 4.1` and `iOS 9.0` or `macOS 10.11` although we recommend using the latest iOS and MacOS versions for your safety. Don't forget to set the iOS version in a Podfile. Otherwise, you get an error if the deployment target is less than the latest SDK.
69+
If you are using web3swift in your app or know of an app that uses it, please add it to [this list](https://github.com/matterinc/web3swift/wiki/Apps-using-web3swift).
70+
71+
- If you **need help**, use [Stack Overflow](https://stackoverflow.com/questions/tagged/web3swift) and tag `web3swift`.
72+
- If you need to **find or understand an API**, check [our documentation](http://web3swift.github.io/web3swift/).
73+
- If you'd like to **see web3swift best practices**, check [Apps using this library](https://github.com/matterinc/web3swift/wiki/Apps-using-web3swift).
74+
- If you **found a bug**, [open an issue](https://github.com/matterinc/web3swift/issues).
75+
- If you **have a feature request**, [open an issue](https://github.com/matterinc/web3swift/issues).
76+
- If you **want to contribute**, [submit a pull request](https://github.com/matterinc/web3swift/pulls).
77+
78+
## Installation
9879

9980
### CocoaPods
10081

@@ -122,205 +103,52 @@ Then, run the following command:
122103
$ pod install
123104
```
124105

125-
## Getting started
126-
127-
Here are a few use cases:
128-
129-
### Create Account
130-
131-
```swift
132-
// Create keystore and account with password.
133-
134-
let keystore = try! EthereumKeystoreV3(password: "changeme"); // generates a private key internally if node "privateKey" parameter supplied
135-
let account = keystore!.addresses![0]
136-
print(account)
137-
138-
let data = try! keystore!.serialize() // internally serializes to JSON
139-
print(try! JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions(rawValue:0)))
140-
let key = try! keystore!.UNSAFE_getPrivateKeyData(password: "changeme", account: account) // you should rarely use this and expose a key manually
141-
```
142-
143-
### Save keystore to the memory
106+
### Carthage
144107

145-
```swift
146-
//First you need a `KeystoreManager` instance:
147-
guard let userDirectory = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first,
148-
let keystoreManager = KeystoreManager.managerForPath(userDirectory + "/keystore")
149-
else {
150-
fatalError("Couldn't create a KeystoreManager.")
151-
}
108+
[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
152109

153-
//Next you create a new Keystore:
110+
You can install Carthage with [Homebrew](https://brew.sh/) using the following command:
154111

155-
let newKeystore = try? EthereumKeystoreV3(password: "YOUR_PASSWORD")
156-
157-
// Then you save the created keystore to the file system:
158-
159-
let newKeystoreJSON = try? JSONEncoder().encode(newKeystore.keystoreParams)
160-
FileManager.default.createFile(atPath: "\(keystoreManager.path)/keystore.json", contents: newKeystoreJSON, attributes: nil)
161-
162-
// Later you can retreive it:
163-
164-
if let address = keystoreManager.addresses?.first,
165-
let retrievedKeystore = keystoreManager.walletForAddress(address) as? EthereumKeystoreV3 {
166-
return retrievedKeystore
167-
}
168-
```
169-
170-
### Initializing Ethereum address
171-
```swift
172-
let coldWalletAddress = EthereumAddress("0x6394b37Cf80A7358b38068f0CA4760ad49983a1B")
173-
let constractAddress = EthereumAddress("0x45245bc59219eeaaf6cd3f382e078a461ff9de7b", ignoreChecksum: true)
174-
```
175-
Ethereum addresses are checksum checked if they are not lowercased or uppercased and always length checked
176-
177-
### Setting options
178-
179-
```swift
180-
var options = Web3Options.defaultOptions()
181-
// public var to: EthereumAddress? = nil - to what address transaction is aimed
182-
// public var from: EthereumAddress? = nil - form what address it should be sent (either signed locally or on the node)
183-
// public var gasLimit: BigUInt? = BigUInt(90000) - default gas limit
184-
// public var gasPrice: BigUInt? = BigUInt(5000000000) - default gas price, quite small
185-
// public var value: BigUInt? = BigUInt(0) - amount of WEI sent along the transaction
186-
options.gasPrice = gasPrice
187-
options.gasLimit = gasLimit
188-
options.from = EthereumAddress("0xE6877A4d8806e9A9F12eB2e8561EA6c1db19978d")
189-
```
190-
191-
### Encoding Transaction
192-
193-
```
194-
//TODO
195-
```
196-
197-
### Signing Transaction
198-
199-
```
200-
//TODO
201-
```
202-
### Getting ETH balance
203-
```swift
204-
let address = EthereumAddress("0xE6877A4d8806e9A9F12eB2e8561EA6c1db19978d")!
205-
let web3Main = Web3.InfuraMainnetWeb3()
206-
let balanceResult = web3Main.eth.getBalance(address)
207-
guard case .success(let balance) = balanceResult else {return}
208-
```
209-
### Getting gas price
210-
```swift
211-
let web3Main = Web3.InfuraMainnetWeb3()
212-
let gasPriceResult = web3Main.eth.getGasPrice()
213-
guard case .success(let gasPrice) = gasPriceResult else {return}
214-
```
215-
216-
### Sending ETH
217-
```swift
218-
let web3Rinkeby = Web3.InfuraRinkebyWeb3()
219-
web3Rinkeby.addKeystoreManager(bip32keystoreManager) // attach a keystore if you want to sign locally. Otherwise unsigned request will be sent to remote node
220-
options.from = bip32ks?.addresses?.first! // specify from what address you want to send it
221-
intermediateSend = web3Rinkeby.contract(Web3.Utils.coldWalletABI, at: coldWalletAddress, abiVersion: 2)!.method(options: options)! // an address with a private key attached in not different from any other address, just has very simple ABI
222-
let sendResultBip32 = intermediateSend.send(password: "changeme")
112+
```bash
113+
$ brew update
114+
$ brew install carthage
223115
```
224116

225-
### ERC20 Iteraction:
117+
To integrate web3swift into your Xcode project using Carthage, specify it in your `Cartfile`:
226118

227-
#### Getting ERC20 token balance
228-
```swift
229-
let contractAddress = EthereumAddress("0x45245bc59219eeaaf6cd3f382e078a461ff9de7b")! // BKX token on Ethereum mainnet
230-
let contract = web3.contract(Web3.Utils.erc20ABI, at: contractAddress, abiVersion: 2)! // utilize precompiled ERC20 ABI for your concenience
231-
guard let bkxBalanceResult = contract.method("balanceOf", parameters: [coldWalletAddress] as [AnyObject], options: options)?.call(options: nil) else {return} // encode parameters for transaction
232-
guard case .success(let bkxBalance) = bkxBalanceResult, let bal = bkxBalance["0"] as? BigUInt else {return} // bkxBalance is [String: Any], and parameters are enumerated as "0", "1", etc in order of being returned. If returned parameter has a name in ABI, it is also duplicated
233-
print("BKX token balance = " + String(bal))
119+
```ogdl
120+
github "web3swift/web3swift" ~> 1.1.9
234121
```
235122

236-
#### Sending ERC20
237-
```swift
238-
var convenienceTransferOptions = Web3Options.defaultOptions()
239-
convenienceTransferOptions.gasPrice = gasPriceRinkeby
240-
let convenienceTokenTransfer = web3Rinkeby.eth.sendERC20tokensWithNaturalUnits(tokenAddress: EthereumAddress("0xa407dd0cbc9f9d20cdbd557686625e586c85b20a")!, from: (ks?.addresses?.first!)!, to: EthereumAddress("0x6394b37Cf80A7358b38068f0CA4760ad49983a1B")!, amount: "0.0001", options: convenienceTransferOptions) // there are also convenience functions to send ETH and ERC20 under the .eth structure
241-
let gasEstimateResult = convenienceTokenTransfer!.estimateGas(options: nil)
242-
guard case .success(let gasEstimate) = gasEstimateResult else {return}
243-
convenienceTransferOptions.gasLimit = gasEstimate
244-
let convenienceTransferResult = convenienceTokenTransfer!.send(password: "changeme", options: convenienceTransferOptions)
245-
switch convenienceTransferResult {
246-
case .success(let res):
247-
print("Token transfer successful")
248-
print(res)
249-
case .failure(let error):
250-
print(error)
251-
}
252-
```
253-
254-
## Apps using this library
255-
256-
If you are using `web3swift` in your app or know of an app that uses it, please add it to this list: [Apps using this library](https://github.com/matterinc/web3swift/wiki/Apps-using-web3swift)
257-
It would be much appreciated! 👍
258-
259-
Here is some examples:
260-
261-
* [MEWconnect-iOS](https://github.com/MyEtherWallet/MEWconnect-iOS)
262-
* [Peepeth iOS client](https://github.com/matterinc/PeepethClient)
263-
* [Ethereum & ERC20Tokens Wallet](https://itunes.apple.com/us/app/ethereum-erc20tokens-wallet/id1386738877?ls=1&mt=8)
264-
* [BankexWallet](https://github.com/BANKEX/Pay-iOS)
265-
* [GeoChain](https://github.com/awallish/GeoChain)
266-
* [TRX-Wallet](https://github.com/NewHorizonLabs/TRX-Wallet)
267-
* [YOUR APP CAN BE THERE (click me)](https://github.com/matterinc/web3swift/wiki/Apps-using-web3swift/_edit) :wink:
268-
269-
If you've used this project in a live app, please let us know!
270-
271-
*If you are using `web3swift` in your app or know of an app that uses it, please add it to [this](https://github.com/matterinc/web3swift/wiki/Apps-using-web3swift) list.*
272-
273-
274-
275-
## Plans
276-
277-
- Full reference `web3js` functionality
278-
- Light Ethereum subprotocol (LES) integration
279-
280-
281-
### Extra features:
282-
283-
For the latest version, please check [develop](https://github.com/matterinc/web3swift/tree/develop) branch.
284-
Changes made to this branch will be merged into the [master](https://github.com/matterinc/web3swift/tree/master) branch at some point.
285-
286-
---
287-
123+
Run `carthage update` to build the framework and drag the built `web3swift.framework` into your Xcode project.
288124

289-
## Stay in touch
290-
291-
When using this pod, please make references to this repo and give your start! :)
292-
*Nothing makes developers happier than seeing someone else use our work and go wild with it.*
293-
294-
295-
If you are using web3swift in your app or know of an app that uses it, please add it to [this list](https://github.com/matterinc/web3swift/wiki/Apps-using-web3swift).
125+
## Example Project
296126

127+
You can try lib by running the example project:
297128

298-
### Contribution
299-
300-
301-
- If you **have a feature request**, [open an issue](https://github.com/matterinc/web3swift/issues).
302-
- If you **want to contribute**, [submit a pull request](https://github.com/matterinc/web3swift/pulls).
129+
- Clone the repo: `git clone https://github.com/matterinc/web3swift.git`
130+
- Move to the repo: `cd web3swift/Example/web3swiftExample`
131+
- Install Dependencies: `pod install`
132+
- Open: `open ./web3swiftExample.xcworkspace`
303133

134+
## Credits
304135

305-
### Communication
136+
Alex Vlasov, [@shamatar](https://github.com/shamatar), [email protected]
306137

307-
- if you **need help**, use [Stack Overflow](https://stackoverflow.com/questions/tagged/web3swift) (tag 'web3swift')
308-
- If you'd like to **ask a general question**, use [Stack Overflow](http://stackoverflow.com/questions/tagged/web3swift).
309-
- If you **found a bug**, [open an issue](https://github.com/matterinc/web3swift/issues).
138+
Petr Korolev, [@skywinder](https://github.com/skywinder)
310139

140+
### Security Disclosure
311141

312-
### Special thanks to
142+
If you believe you have identified a security vulnerability with web3swift, you should report it as soon as possible via email to [Alex Vlasov]([email protected]). Please do not post it to a public issue tracker.
313143

314-
- Gnosis team and their library [Bivrost-swift](https://github.com/gnosis/bivrost-swift) for inspiration for the ABI decoding approach
315-
- [Trust iOS Wallet](https://github.com/TrustWallet/trust-wallet-ios) for the collaboration and discussion of the initial idea
316-
- Official Ethereum and Solidity docs, everything was written from ground truth standards
317-
-
318-
## Authors
144+
## Donations
319145

320-
Alex Vlasov, [@shamatar](https://github.com/shamatar), [email protected]
146+
The [Matter](https://github.com/orgs/matterinc/people) are charged with open-sorсe and do not require money for using their web3swift lib.
147+
We want to continue to do everything we can to move the needle forward.
148+
If you use any of our libraries for work, see if your employers would be interested in donating. Any amount you can donate today to help us reach our goal would be greatly appreciated.
321149

322-
Petr Korolev, [@skywinder](https://github.com/skywinder)
150+
//TODO: - Donate
323151

324152
## License
325153

326-
web3swift is available under the Apache License 2.0 license. See the [LICENSE](https://github.com/matterinc/web3swift/blob/master/LICENSE) file for more info.
154+
web3swift is available under the Apache License 2.0 license. See the [LICENSE](https://github.com/matterinc/web3swift/blob/master/LICENSE) for details.

0 commit comments

Comments
 (0)