Skip to content

Commit c6f072e

Browse files
committed
Merge branch 'develop' into master
2 parents 5976233 + 3f59fc4 commit c6f072e

File tree

13 files changed

+160
-220
lines changed

13 files changed

+160
-220
lines changed

CHANGELOG.md

Lines changed: 49 additions & 192 deletions
Large diffs are not rendered by default.

Documentation/Usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ let tx = contract.write(
319319
transactionOptions: options)!
320320
```
321321

322-
##### Read Transaction to call smart contract method
322+
##### Read Transaction from call smart contract method
323323

324324
```swift
325325
let walletAddress = EthereumAddress(wallet.address)! // Your wallet address

Documentation/web3swift 2.0 Migration Guide.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ This guide is provided in order to ease the transition of existing applications
4444

4545
---
4646

47-
## Follow naming convention
48-
49-
Now you have to do "import Web3swift" (capitalization!) instead of "import web3swift" to follow naming convention.
50-
5147
## New pods
5248

5349
Now EthereumAddress and Ethereum ABI are separate projects. Use "//import EthereumAddress" and "import Ethereum ABI" everywhere you use them.
@@ -256,7 +252,7 @@ let balanceString = Web3.Utils.formatToEthereumUnits(balance, toUnits: .eth, dec
256252

257253
// web3swift 2.0
258254
let address = EthereumAddress("<Address>")!
259-
let web3Main = Web3.InfuraMainnetWeb3()
255+
let web3 = Web3.InfuraMainnetWeb3()
260256
let balance = try web3.eth.getBalance(address: address)
261257
let balanceString = Web3.Utils.formatToEthereumUnits(balance, toUnits: .eth, decimals: 3)
262258
```

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let package = Package(
1010
.library(name: "web3swift", targets: ["web3swift"]),
1111
],
1212
dependencies: [
13-
.package(url: "https://github.com/attaswift/BigInt.git", from: "3.1.0"),
13+
.package(url: "https://github.com/attaswift/BigInt.git", from: "5.0"),
1414
.package(url: "https://github.com/mxcl/PromiseKit.git", from: "6.8.4"),
1515
.package(url: "https://github.com/daltoniam/Starscream.git", from: "3.1.0"),
1616
.package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", from: "1.0.0"),

README.md

Lines changed: 93 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
- [Core features](#core-features)
2121
- [Installation](#installation)
2222
- [Example usage](#example-usage)
23+
- [Send Ether](#send-ether)
24+
- [Send ERC-20 Token](#send-erc-20-token)
25+
- [Write Transaction and call smart contract method](#write-transaction-and-call-smart-contract-method)
26+
- [Web3View example](#web3view-example)
27+
- [Build from source](#build-from-source)
2328
- [Requirements](#requirements)
2429
- [Migration Guides](#migration-guides)
2530
- [Documentation](#documentation)
@@ -51,7 +56,7 @@
5156

5257
- [x] **[BIP32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki) (HD Wallets), [BIP39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) (Seed phrases), [BIP44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki) (Key generation prefixes)**
5358
- [x] **[EIP-20](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md)** (Standart interface for tokens - ERC-20), **[EIP-67](https://github.com/ethereum/EIPs/issues/67)** (Standard URI scheme), **[EIP-155](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md)** (Replay attacks protection)
54-
- [x] **And many others ** *(For more details about this EIP's look at [Documentation page](https://github.com/matter-labs/web3swift/blob/master/Documentation/))*: EIP-681, EIP-721, EIP-165, EIP-777, EIP-820, EIP-888, EIP-1400, EIP-1410, EIP-1594, EIP-1643, EIP-1644, EIP-1633, EIP-721, EIP-1155, EIP-1376, ST-20
59+
- [x] **And many others** *(For details about this EIP's look at [Documentation page](https://github.com/matter-labs/web3swift/blob/master/Documentation/))*: EIP-681, EIP-721, EIP-165, EIP-777, EIP-820, EIP-888, EIP-1400, EIP-1410, EIP-1594, EIP-1643, EIP-1644, EIP-1633, EIP-721, EIP-1155, EIP-1376, ST-20
5560

5661
- [x] 🗜 **Batched requests** in concurrent mode
5762
- [x] **RLP encoding**
@@ -116,9 +121,91 @@ github "matter-labs/web3swift" "master"
116121

117122
Run `carthage update` to build the framework. By default, Carthage performs checkouts and creates a new directory 'Carthage' in the same location as your Cartfile. Open this directory, go to 'Build' directory, choose iOS or macOS directory, and use the selected directory framework in your Xcode project.
118123

124+
- Swift Package
125+
Open xcode setting and add this repo as a source
126+
119127
### Example usage
120128

121-
**Web3View example:**
129+
130+
##### Send Ether
131+
132+
```swift
133+
let value: String = "1.0" // In Ether
134+
let walletAddress = EthereumAddress(wallet.address)! // Your wallet address
135+
let toAddress = EthereumAddress(toAddressString)!
136+
let contract = web3.contract(Web3.Utils.coldWalletABI, at: toAddress, abiVersion: 2)!
137+
let amount = Web3.Utils.parseToBigUInt(value, units: .eth)
138+
var options = TransactionOptions.defaultOptions
139+
options.value = amount
140+
options.from = walletAddress
141+
options.gasPrice = .automatic
142+
options.gasLimit = .automatic
143+
let tx = contract.write(
144+
"fallback",
145+
parameters: [AnyObject](),
146+
extraData: Data(),
147+
transactionOptions: options)!
148+
```
149+
150+
##### Send ERC-20 Token
151+
152+
```swift
153+
let web3 = Web3.InfuraMainnetWeb3()
154+
let value: String = "1.0" // In Tokens
155+
let walletAddress = EthereumAddress(wallet.address)! // Your wallet address
156+
let toAddress = EthereumAddress(toAddressString)!
157+
let erc20ContractAddress = EthereumAddress(token.address)!
158+
let contract = web3.contract(Web3.Utils.erc20ABI, at: erc20ContractAddress, abiVersion: 2)!
159+
let amount = Web3.Utils.parseToBigUInt(value, units: .eth)
160+
var options = TransactionOptions.defaultOptions
161+
options.value = amount
162+
options.from = walletAddress
163+
options.gasPrice = .automatic
164+
options.gasLimit = .automatic
165+
let method = "transfer"
166+
let tx = contract.write(
167+
method,
168+
parameters: [toAddress, amount] as [AnyObject],
169+
extraData: Data(),
170+
transactionOptions: options)!
171+
```
172+
173+
174+
##### Get account balance
175+
```swift
176+
let web3 = Web3.InfuraMainnetWeb3()
177+
let address = EthereumAddress("<Address>")!
178+
let balance = try web3.eth.getBalance(address: address)
179+
let balanceString = Web3.Utils.formatToEthereumUnits(balance, toUnits: .eth, decimals: 3)
180+
```
181+
182+
##### Write Transaction and call smart contract method
183+
184+
```swift
185+
let web3 = Web3.InfuraMainnetWeb3()
186+
let value: String = "0.0" // Any amount of Ether you need to send
187+
let walletAddress = EthereumAddress(wallet.address)! // Your wallet address
188+
let contractMethod = "SOMECONTRACTMETHOD" // Contract method you want to write
189+
let contractABI = "..." // Contract ABI
190+
let contractAddress = EthereumAddress(contractAddressString)!
191+
let abiVersion = 2 // Contract ABI version
192+
let parameters: [AnyObject] = [...]() // Parameters for contract method
193+
let extraData: Data = Data() // Extra data for contract method
194+
let contract = web3.contract(contractABI, at: contractAddress, abiVersion: abiVersion)!
195+
let amount = Web3.Utils.parseToBigUInt(value, units: .eth)
196+
var options = TransactionOptions.defaultOptions
197+
options.value = amount
198+
options.from = walletAddress
199+
options.gasPrice = .automatic
200+
options.gasLimit = .automatic
201+
let tx = contract.write(
202+
contractMethod,
203+
parameters: parameters,
204+
extraData: extraData,
205+
transactionOptions: options)!
206+
```
207+
208+
### Web3View example
122209

123210
You can see how to our demo project: **WKWebView with injected "web3" provider**:
124211

@@ -129,10 +216,10 @@ pod install
129216
open ./web3swiftBrowser.xcworkspace
130217
```
131218

132-
### Build from source:
219+
### Build from source
133220

134221
- Clone repo
135-
- Instal dependencies via `./carthage-build.sh --platform iOS` (temo workaround, foe of Carthage bug.For more details please look at https://github.com/Carthage/Carthage/issues/3019#issuecomment-665136323)
222+
- Instal dependencies via `./carthage-build.sh --platform iOS` (temp workaround, foe of Carthage bug. [For details please look at](https://github.com/Carthage/Carthage/issues/3019#issuecomment-665136323)
136223

137224
### Requirements
138225

@@ -206,9 +293,9 @@ If you use any of our libraries for work, see if your employers would be interes
206293
We want to continue to do everything we can to move the needle forward.
207294

208295
- **Support us** via [@gitcoin Grant program](https://gitcoin.co/grants/358/web3swift)
209-
- Ether wallet address: `0xe22b8979739d724343bd002f9f432f5990879901`
296+
- Ether wallet address: `0x6A3738c6299f45c31697aceA647D49EdCC9C28A4`
210297

211-
![Donate](http://qrcoder.ru/code/?0xe22b8979739d724343bd002f9f432f5990879901&4&0)
298+
<img src="https://raw.githubusercontent.com/matter-labs/web3swift/develop/img/Ether-donations.jpeg" width="300" />
212299

213300
### Future steps
214301

Sources/web3swift/Browser/Bridge.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
// Copyright © 2017 Samaritan. All rights reserved.
77
//
88

9-
import UIKit
109
import WebKit
1110

1211
/// Bridge for WKWebView and JavaScript
@@ -197,7 +196,7 @@ public extension WKWebView {
197196
}
198197

199198
/// Bridge for WKWebView and JavaScript. Initialize `lazy`
200-
public var bridge: Bridge {
199+
var bridge: Bridge {
201200
if let bridge = objc_getAssociatedObject(self, &STPrivateStatic.bridgeKey) as? Bridge {
202201
return bridge
203202
}
@@ -207,7 +206,7 @@ public extension WKWebView {
207206
}
208207

209208
/// Remove Bridge And Reset, All the handlers will be removed
210-
public func removeBridge() {
209+
func removeBridge() {
211210
if let bridge = objc_getAssociatedObject(self, &STPrivateStatic.bridgeKey) as? Bridge {
212211
let userContentController = bridge.configuration.userContentController
213212
userContentController.removeScriptMessageHandler(forName: Bridge.name)
@@ -218,7 +217,7 @@ public extension WKWebView {
218217

219218
fileprivate extension WKWebView {
220219

221-
fileprivate func st_dispatchBridgeEvent(_ eventName: String,
220+
func st_dispatchBridgeEvent(_ eventName: String,
222221
parameters: [String: Any],
223222
results: Bridge.Results,
224223
completionHandler: ((Any?, Error?) -> Void)? = nil) {

Sources/web3swift/Browser/BrowserViewController.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
// Copyright © 2020 Matter Labs. All rights reserved.
77
//
88

9-
import UIKit
109
import WebKit
1110

1211
open class BrowserViewController: UIViewController {

Sources/web3swift/SwiftRLP/RLP.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public struct RLP {
193193
return false
194194
case .data(_):
195195
return true
196-
case .list(_):
196+
case .list(_, _, _):
197197
return false
198198
}
199199
}
@@ -204,7 +204,7 @@ public struct RLP {
204204
return false
205205
case .data(_):
206206
return false
207-
case .list(_):
207+
case .list(_,_,_):
208208
return true
209209
}
210210
}

Sources/web3swift/Transaction/BloomFilter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ extension EthereumBloomFilter {
3232
}
3333

3434
static func bloom9(_ data: Data) -> BigUInt {
35-
var b = data.sha3(.keccak256)
35+
let b = data.sha3(.keccak256)
3636
var r = BigUInt(0)
3737
let mask = BigUInt(2047)
3838
for i in stride(from: 0, to: 6, by: 2) {

Sources/web3swift/Transaction/EthereumTransaction.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public struct EthereumTransaction: CustomStringConvertible {
1717
// The destination address of the message, left undefined for a contract-creation transaction.
1818
public var to: EthereumAddress
1919
// (optional) The value transferred for the transaction in wei, also the endowment if it’s a contract-creation transaction.
20+
// TODO - split EthereumTransaction to two classes: with optional and required value property, depends on type of transaction
2021
public var value: BigUInt?
2122
public var data: Data
2223
public var v: BigUInt = BigUInt(1)
@@ -165,18 +166,18 @@ public struct EthereumTransaction: CustomStringConvertible {
165166
public func encode(forSignature:Bool = false, chainID: BigUInt? = nil) -> Data? {
166167
if (forSignature) {
167168
if chainID != nil {
168-
let fields = [self.nonce, self.gasPrice, self.gasLimit, self.to.addressData, self.value, self.data, chainID!, BigUInt(0), BigUInt(0)] as [AnyObject]
169+
let fields = [self.nonce, self.gasPrice, self.gasLimit, self.to.addressData, self.value!, self.data, chainID!, BigUInt(0), BigUInt(0)] as [AnyObject]
169170
return RLP.encode(fields)
170171
}
171172
else if self.chainID != nil {
172-
let fields = [self.nonce, self.gasPrice, self.gasLimit, self.to.addressData, self.value, self.data, self.chainID!, BigUInt(0), BigUInt(0)] as [AnyObject]
173+
let fields = [self.nonce, self.gasPrice, self.gasLimit, self.to.addressData, self.value!, self.data, self.chainID!, BigUInt(0), BigUInt(0)] as [AnyObject]
173174
return RLP.encode(fields)
174175
} else {
175-
let fields = [self.nonce, self.gasPrice, self.gasLimit, self.to.addressData, self.value, self.data] as [AnyObject]
176+
let fields = [self.nonce, self.gasPrice, self.gasLimit, self.to.addressData, self.value!, self.data] as [AnyObject]
176177
return RLP.encode(fields)
177178
}
178179
} else {
179-
let fields = [self.nonce, self.gasPrice, self.gasLimit, self.to.addressData, self.value, self.data, self.v, self.r, self.s] as [AnyObject]
180+
let fields = [self.nonce, self.gasPrice, self.gasLimit, self.to.addressData, self.value!, self.data, self.v, self.r, self.s] as [AnyObject]
180181
return RLP.encode(fields)
181182
}
182183
}

0 commit comments

Comments
 (0)