You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- **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
- Not every JSON RPC function is exposed yet, and priority is given to the ones required for mobile devices
79
50
- Functionality was focused on serializing and signing transactions locally on the device to send raw transactions to Ethereum network
80
51
- Requirements for password input on every transaction are indeed a design decision. Interface designers can save user passwords with the user's consent
81
52
- 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
82
53
83
-
## Example
54
+
## Requirements
84
55
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+
86
59
87
-
- Clone the repo: `git clone https://github.com/matterinc/web3swift.git`
88
-
- Move to the repo: `cd web3swift/Example/web3swiftExample`
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.*
96
68
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
98
79
99
80
### CocoaPods
100
81
@@ -122,205 +103,52 @@ Then, run the following command:
122
103
$ pod install
123
104
```
124
105
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
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.
152
109
153
-
//Next you create a new Keystore:
110
+
You can install Carthage with [Homebrew](https://brew.sh/) using the following command:
154
111
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)
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
223
115
```
224
116
225
-
### ERC20 Iteraction:
117
+
To integrate web3swift into your Xcode project using Carthage, specify it in your `Cartfile`:
226
118
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
-
guardlet bkxBalanceResult = contract.method("balanceOf", parameters: [coldWalletAddress] as [AnyObject], options: options)?.call(options: nil) else {return} // encode parameters for transaction
232
-
guardcase .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
234
121
```
235
122
236
-
#### Sending ERC20
237
-
```swift
238
-
var convenienceTransferOptions = Web3Options.defaultOptions()
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)
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)
*[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.
288
124
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
296
126
127
+
You can try lib by running the example project:
297
128
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`
303
133
134
+
## Credits
304
135
305
-
### Communication
136
+
Alex Vlasov, [@shamatar](https://github.com/shamatar), [email protected]
306
137
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)
310
139
140
+
### Security Disclosure
311
141
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.
313
143
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
319
145
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.
321
149
322
-
Petr Korolev, [@skywinder](https://github.com/skywinder)
150
+
//TODO: - Donate
323
151
324
152
## License
325
153
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