Skip to content

Commit 4905e33

Browse files
doc fix
1 parent 422da5b commit 4905e33

File tree

2 files changed

+121
-39
lines changed

2 files changed

+121
-39
lines changed

Documentation/Usage.md

Lines changed: 83 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,19 @@
2828
- [Send write transaction](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#writing)
2929
- [Send read transaction](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#reading)
3030
- [Get Block number](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#get-block-number)
31-
- **[Infura Websockets](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#infura-websockets)**
32-
- [Subscribe on new pending transactions](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#subscribe-on-new-pending-transactions)
31+
- **[Websockets](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#websockets)**
32+
- [Web3socketDelegate](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#web3socketdelegate)
3333
- [Get latest new pending transactions](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#get-latest-new-pending-transactions)
34+
- *[Custom Websocket Provider](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#custom-websocket-provider)*
35+
- [Connect to custom endpoint](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#connect-to-custom-endpoint)
36+
- [Send message](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#send-message)
37+
- *[Infura Websocket Provider](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#infura-websocket-provider)*
38+
- [Connect to Infura endpoint](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#connect-to-infura-endpoint)
39+
- [Connect to custom endpoint with API similar to Infura WSS endpoint](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#connect-to-custom-endpoint-with-api-similar-to-infura-wss-endpoint)
40+
- [Create a filter in the node to notify when something happened](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#create-a-filter-in-the-node-to-notify-when-something-happened)
41+
- [Get new pending transactions](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#get-new-pending-transactions)
42+
- [Create a new subscription over particular events](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#create-a-new-subscription-over-particular-events)
43+
- [Subscribe on new pending transactions](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#subscribe-on-new-pending-transactions)
3444

3545
## Introduction
3646

@@ -149,7 +159,7 @@ if wallet.isHD {
149159
}
150160
```
151161

152-
#### Get wallet Private key
162+
### Get wallet Private key
153163

154164
```swift
155165
let password = "web3swift"
@@ -335,20 +345,83 @@ let result = try! transaction.call()
335345
let blockNumber = try! web3.eth.getBlockNumber()
336346
```
337347

338-
## Infura Websockets
348+
## Websockets
339349

340-
### Subscribe on new pending transactions
350+
### Web3socketDelegate
341351

352+
To receive messages from endpoint you need to create a class that adopt to Web3SocketDelegate protocol.
342353
```swift
343354
let delegate: Web3SocketDelegate = DelegateClass() // Some delegate class which will receive messages from endpoint
344-
let socketProvider = InfuraWebsocketProvider.connectToSocket(.Mainnet, delegate: delegate)
345-
try! socketProvider.subscribeOnNewPendingTransactions()
355+
```
356+
357+
### Custom Websocket Provider
358+
359+
#### Connect to custom endpoint
360+
361+
You can create WebsocketProvider and connect/disconnect it.
362+
```swift
363+
let socketProvider = WebsocketProvider("ws://your.endpoint", delegate: delegate)
364+
socketProvider.connectSocket()
365+
/// Some code
366+
/// ...
367+
socketProvider.disconnectSocket()
368+
```
369+
370+
Or you can create already connected WebsocketProvider
371+
```swift
372+
let socketProvider = WebsocketProvider.connectToSocket("ws://your.endpoint", delegate: delegate)
346373
```
347374

348-
### Get latest new pending transactions
375+
#### Send message
376+
377+
```swift
378+
// String message
379+
socketProvider.writeMessage(String())
380+
// Data message
381+
socketProvider.writeMessage(Data())
382+
```
383+
384+
### Infura Websocket Provider
385+
386+
#### Connect to Infura endpoint
387+
388+
```swift
389+
let socketProvider = InfuraWebsocketProvider.connectToInfuraSocket(.Mainnet, delegate: delegate)
390+
```
391+
392+
#### Connect to custom endpoint with API similar to Infura WSS endpoint
393+
394+
```swift
395+
let socketProvider = InfuraWebsocketProvider.connectToSocket("ws://your.endpoint", delegate: delegate)
396+
```
397+
398+
#### Create a filter in the node to notify when something happened
399+
400+
To study possible filters read [Infura WSS filters documentation](https://infura.io/docs/ethereum/wss/introduction)
401+
402+
```swift
403+
try! socketProvider.filter(method: <InfuraWebsocketMethod>, params: <[Encodable]?>)
404+
```
405+
406+
#### Get new pending transactions
349407

350408
```swift
351-
let delegate: Web3SocketDelegate = DelegateClass() // Some delegate class which will receive messages from endpoint
352-
let socketProvider = InfuraWebsocketProvider.connectToSocket(.Mainnet, delegate: delegate)
353409
try! socketProvider.filter(method: .newPendingTransactionFilter)
354410
```
411+
412+
#### Create a new subscription over particular events
413+
414+
To study possible subscriptions read [Infura WSS subscriptions documentation](https://infura.io/docs/ethereum/wss/eth_subscribe)
415+
416+
```swift
417+
try! socketProvider.subscribe(params: <[Encodable]>)
418+
```
419+
420+
#### Subscribe on new pending transactions
421+
422+
```swift
423+
try! socketProvider.subscribeOnNewPendingTransactions()
424+
```
425+
426+
427+

README.md

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,36 +33,45 @@
3333
---
3434
- [Usage Doc](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md)
3535
- **[Introduction](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#introduction)**
36-
- *[Preffered models](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#preffered-models)*
37-
- [Preffered keys Wallet Model](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#preffered-keys-wallet-model-account)
38-
- [Preffered ERC-20 Model](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#preffered-erc-20-model)
39-
- **[Account Management](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#account-management)**
40-
- *[Create Account](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#create-account)*
41-
- [Create Account With Private Key](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#create-account-with-private-key)
42-
- [Create Account With Mnemonics Phrase](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#create-account-with-mnemonics-phrase)
43-
- *[Import Account](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#create-account)*
44-
- [Import Account With Private Key](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#import-account-with-private-key)
45-
- [Import Account With Mnemonics Phrase](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#import-account-with-mnemonics-phrase)
46-
- [Get Keystore Manager from wallet data](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#get-keystore-manager-from-wallet-data)
47-
- [Get wallet Private key](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#get-wallet-private-key)
48-
- **[Ethereum Endpoints interaction](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#ethereum-endpoints-interaction)**
49-
- [web3 instance](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#web3-instance)
50-
- [Ethereum Address](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#ethereum-address)
51-
- *[Get Balance](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#get-balance)*
52-
- [Getting ETH balance](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#getting-eth-balance)
53-
- [Getting ERC20 token balance](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#getting-erc20-token-balance)
54-
- *[Transactions Operations](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#transactions-operations)*
55-
- [Preparing Transaction For Sending Ether](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#preparing-transaction-for-sending-ether)
56-
- [Preparing Transaction For Sending ERC-20 Tokens](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#preparing-transaction-for-sending-erc-20-tokens)
57-
- [Preparing Write Transaction for sending to some Contract and use its method](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#preparing-write-transaction-for-sending-to-some-contract-and-use-its-method)
58-
- [Preparing Read Transaction to call some Contract method](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#preparing-read-transaction-to-call-some-contract-method)
59-
- [Send write transaction](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#writing)
60-
- [Send read transaction](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#reading)
61-
- [Get Block number](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#get-block-number)
62-
- **[Infura Websockets](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#infura-websockets)**
36+
- *[Preffered models](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#preffered-models)*
37+
- [Preffered keys Wallet Model](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#preffered-keys-wallet-model-account)
38+
- [Preffered ERC-20 Model](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#preffered-erc-20-model)
39+
- **[Account Management](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#account-management)**
40+
- *[Create Account](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#create-account)*
41+
- [Create Account With Private Key](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#create-account-with-private-key)
42+
- [Create Account With Mnemonics Phrase](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#create-account-with-mnemonics-phrase)
43+
- *[Import Account](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#create-account)*
44+
- [Import Account With Private Key](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#import-account-with-private-key)
45+
- [Import Account With Mnemonics Phrase](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#import-account-with-mnemonics-phrase)
46+
- [Get Keystore Manager from wallet data](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#get-keystore-manager-from-wallet-data)
47+
- [Get wallet Private key](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#get-wallet-private-key)
48+
- **[Ethereum Endpoints interaction](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#ethereum-endpoints-interaction)**
49+
- [web3 instance](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#web3-instance)
50+
- [Ethereum Address](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#ethereum-address)
51+
- *[Get Balance](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#get-balance)*
52+
- [Getting ETH balance](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#getting-eth-balance)
53+
- [Getting ERC20 token balance](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#getting-erc20-token-balance)
54+
- *[Transactions Operations](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#transactions-operations)*
55+
- [Preparing Transaction For Sending Ether](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#preparing-transaction-for-sending-ether)
56+
- [Preparing Transaction For Sending ERC-20 Tokens](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#preparing-transaction-for-sending-erc-20-tokens)
57+
- [Preparing Write Transaction for sending to some Contract and use its method](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#preparing-write-transaction-for-sending-to-some-contract-and-use-its-method)
58+
- [Preparing Read Transaction to call some Contract method](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#preparing-read-transaction-to-call-some-contract-method)
59+
- [Send write transaction](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#writing)
60+
- [Send read transaction](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#reading)
61+
- [Get Block number](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#get-block-number)
62+
- **[Websockets](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#websockets)**
63+
- [Web3socketDelegate](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#web3socketdelegate)
64+
- [Get latest new pending transactions](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#get-latest-new-pending-transactions)
65+
- *[Custom Websocket Provider](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#custom-websocket-provider)*
66+
- [Connect to custom endpoint](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#connect-to-custom-endpoint)
67+
- [Send message](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#send-message)
68+
- *[Infura Websocket Provider](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#infura-websocket-provider)*
69+
- [Connect to Infura endpoint](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#connect-to-infura-endpoint)
70+
- [Connect to custom endpoint with API similar to Infura WSS endpoint](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#connect-to-custom-endpoint-with-api-similar-to-infura-wss-endpoint)
71+
- [Create a filter in the node to notify when something happened](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#create-a-filter-in-the-node-to-notify-when-something-happened)
72+
- [Get new pending transactions](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#get-new-pending-transactions)
73+
- [Create a new subscription over particular events](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#create-a-new-subscription-over-particular-events)
6374
- [Subscribe on new pending transactions](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#subscribe-on-new-pending-transactions)
64-
- [Get latest new pending transactions](https://github.com/matter-labs/web3swift/blob/documentation/Documentation/Usage.md#get-latest-new-pending-transactions)
65-
6675
## Ready Features
6776

6877
- [x] Swift implementation of [web3.js](https://github.com/ethereum/web3.js/) functionality :zap:

0 commit comments

Comments
 (0)