Skip to content

Commit

Permalink
update grammar & typos
Browse files Browse the repository at this point in the history
  • Loading branch information
skywinder committed Jun 14, 2019
1 parent ca224b9 commit 515f80e
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 120 deletions.
188 changes: 94 additions & 94 deletions Documentation/Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,71 +7,71 @@
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
- [About source and GitHub repositories](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#about-source-and-github-repositories)

- [Introduction](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#introduction)
- [Preffered models](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#preffered-models)
- [Preffered keys Wallet Model (Account)](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#preffered-keys-wallet-model-account)
- [Preffered ERC-20 Model](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#preffered-erc-20-model)
- [Account Management](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#account-management)
- [Create Account](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#create-account)
- [With Private Key](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#with-private-key)
- [With Mnemonics Phrase](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#with-mnemonics-phrase)
- [Import Account](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#import-account)
- [With Private Key](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#with-private-key-1)
- [With Mnemonics Phrase](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#with-mnemonics-phrase-1)
- [Get Keystore Manager from wallet data](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#get-keystore-manager-from-wallet-data)
- [Get wallet private key](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#get-wallet-private-key)
- [Ethereum Endpoints interaction](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#ethereum-endpoints-interaction)
- [web3 instance](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#web3-instance)
- [Ethereum Address](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#ethereum-address)
- [Initializing](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#initializing)
- [Get Balance](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#get-balance)
- [Get ETH balance](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#get-eth-balance)
- [Get ERC20 token balance](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#get-erc20-token-balance)
- [Transactions Operations](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#transactions-operations)
- [Prepare Transaction](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#prepare-transaction)
- [Send Ether](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#send-ether)
- [Send ERC-20 Token](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#send-erc-20-token)
- [Write Transaction and call smart contract method](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#write-transaction-and-call-smart-contract-method)
- [Read Transaction to call smart contract method](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#read-transaction-to-call-smart-contract-method)
- [Send Transaction](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#send-transaction)
- [Write](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#write)
- [Read](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#read)
- [Chain state](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#chain-state)
- [Get Block number](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#get-block-number)
- [Websockets](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#websockets)
- [Web3socketDelegate](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#web3socketdelegate)
- [Custom Websocket Provider](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#custom-websocket-provider)
- [Connect to custom endpoint](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#connect-to-custom-endpoint)
- [Send message](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#send-message)
- [Infura Websocket interactions](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#infura-websocket-interactions)
- [Connect to Infura endpoint](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#connect-to-infura-endpoint)
- [Connect to custom Infura-like endpoint](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#connect-to-custom-infura-like-endpoint)
- [Create a filter in the node to notify when something happened](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#create-a-filter-in-the-node-to-notify-when-something-happened)
- [Get new pending transactions](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#get-new-pending-transactions)
- [Create a new subscription over particular events](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#create-a-new-subscription-over-particular-events)
- [Subscribe on new pending transactions](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#subscribe-on-new-pending-transactions)
- [ENS](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#ens)
- [Registry](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#registry)
- [Resolver](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#resolver)
- [BaseRegistrar](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#baseregistrar)
- [RegistrarController](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#registrarcontroller)
- [ReverseRegistrar](https://github.com/matter-labs/web3swift/blob/master/Documentation/Usage.md#reverseregistrar)
- [Introduction](#introduction)
- [Preffered models](#preffered-models)
- [Preferred keys Wallet Model (Account)](#preferred-keys-wallet-model-account)
- [Preffered ERC-20 Model](#preffered-erc-20-model)
- [Account Management](#account-management)
- [Create Account](#create-account)
- [With Private Key](#with-private-key)
- [With Mnemonics Phrase](#with-mnemonics-phrase)
- [Import Account](#import-account)
- [With Private Key](#with-private-key-1)
- [With Mnemonics Phrase](#with-mnemonics-phrase-1)
- [Get Keystore Manager from wallet data](#get-keystore-manager-from-wallet-data)
- [Get private key](#get-private-key)
- [Ethereum Endpoints interaction](#ethereum-endpoints-interaction)
- [web3 instance](#web3-instance)
- [Ethereum Address](#ethereum-address)
- [Initializing](#initializing)
- [Get Balance](#get-balance)
- [Get ETH balance](#get-eth-balance)
- [Get ERC20 token balance](#get-erc20-token-balance)
- [Transactions Operations](#transactions-operations)
- [Prepare Transaction](#prepare-transaction)
- [Send Ether](#send-ether)
- [Send ERC-20 Token](#send-erc-20-token)
- [Write Transaction and call smart contract method](#write-transaction-and-call-smart-contract-method)
- [Read Transaction to call smart contract method](#read-transaction-to-call-smart-contract-method)
- [Send Transaction](#send-transaction)
- [Write](#write)
- [Read](#read)
- [Chain state](#chain-state)
- [Get Block number](#get-block-number)
- [Websockets](#websockets)
- [Web3socketDelegate](#web3socketdelegate)
- [Custom Websocket Provider](#custom-websocket-provider)
- [Connect to custom endpoint](#connect-to-custom-endpoint)
- [Send message](#send-message)
- [Infura Websocket interactions](#infura-websocket-interactions)
- [Connect to Infura endpoint](#connect-to-infura-endpoint)
- [Connect to custom Infura-like endpoint](#connect-to-custom-infura-like-endpoint)
- [Create a filter in the node to notify when something happened](#create-a-filter-in-the-node-to-notify-when-something-happened)
- [Get new pending transactions](#get-new-pending-transactions)
- [Create a new subscription over particular events](#create-a-new-subscription-over-particular-events)
- [Subscribe on new pending transactions](#subscribe-on-new-pending-transactions)
- [ENS](#ens)
- [Registry](#registry)
- [Resolver](#resolver)
- [BaseRegistrar](#baseregistrar)
- [RegistrarController](#registrarcontroller)
- [ReverseRegistrar](#reverseregistrar)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## Introduction

To work with platforms based on blockchain technology, in particular with Ethereum-like blockchains, developer must be fluent in concepts such as a crypto wallet, private and public key, smart contract, token and others. We will use these concepts without explaining their meanings. For more information about Ethereum, we recommend reading the book [Mastering Ethereum](https://github.com/ethereumbook/ethereumbook), by Andreas M. Antonopoulos and Gavin Wood.
To work with platforms based on blockchain technology, in particular with Ethereum-like blockchains, a developer must be fluent in concepts such as a crypto wallet, private and public key, smart contract, token and others. We will use these concepts without explaining their meanings. For more information about Ethereum, we recommend reading the book [Mastering Ethereum](https://github.com/ethereumbook/ethereumbook), by Andreas M. Antonopoulos and Gavin Wood.

**To create keystore we forced our users to use some password, which will be used in some operations, like transactions sending. We believe that security is important for such operations and this increases its level. You are free to use a pre-compiled password in your code, that is not set by the keystore user, at your own risk.**
**To create keystore we forced our users to use some password, which will be used in some operations, like transactions sending. We believe that security is essential for such, and this increases its level. You are free to use a pre-compiled password in your code, that is not set by the keystore user, at your own risk.**

*In code examples we used force-unwrapped Swift optionals for better readability of example code. We recommend that you do not use this method to get rid of optional values.*

### Preffered models

To describe the library's capabilities, we will use the models described below, however you can use the models that are convenient for you.
To describe the library's capabilities, we will use the models described below. However, you can use the models that are convenient for you.

#### Preffered keys Wallet Model (Account)
#### Preferred keys Wallet Model (Account)

```swift
struct Wallet {
Expand Down Expand Up @@ -120,10 +120,10 @@ let password = "web3swift"
let bitsOfEntropy: Int = 128 // Entropy is a measure of password strength. Usually used 128 or 256 bits.
let mnemonics = try! BIP39.generateMnemonics(bitsOfEntropy: bitsOfEntropy)!
let keystore = try! BIP32Keystore(
mnemonics: mnemonics,
password: password,
mnemonicsPassword: "",
language: .english)!
mnemonics: mnemonics,
password: password,
mnemonicsPassword: "",
language: .english)!
let name = "New HD Wallet"
let keyData = try! JSONEncoder().encode(keystore.keystoreParams)
let address = keystore.addresses!.first!.address
Expand Down Expand Up @@ -152,10 +152,10 @@ let wallet = Wallet(address: address, data: keyData, name: name, isHD: false)
let password = "web3swift"
let mnemonics = "fine have legal roof fury bread egg knee wrong idea must edit" // Some mnemonic phrase
let keystore = try! BIP32Keystore(
mnemonics: mnemonics,
password: password,
mnemonicsPassword: "",
language: .english)!
mnemonics: mnemonics,
password: password,
mnemonicsPassword: "",
language: .english)!
let name = "New HD Wallet"
let keyData = try! JSONEncoder().encode(keystore.keystoreParams)
let address = keystore.addresses!.first!.address
Expand All @@ -168,15 +168,15 @@ let wallet = Wallet(address: address, data: keyData, name: name, isHD: true)
let data = wallet.data
let keystoreManager: KeystoreManager
if wallet.isHD {
let keystore = BIP32Keystore(data)!
keystoreManager = KeystoreManager([keystore])
let keystore = BIP32Keystore(data)!
keystoreManager = KeystoreManager([keystore])
} else {
let keystore = EthereumKeystoreV3(data)!
keystoreManager = KeystoreManager([keystore])
let keystore = EthereumKeystoreV3(data)!
keystoreManager = KeystoreManager([keystore])
}
```

### Get wallet private key
### Get private key

```swift
let password = "web3swift"
Expand Down Expand Up @@ -237,10 +237,10 @@ options.gasPrice = .automatic
options.gasLimit = .automatic
let method = "balanceOf"
let tx = contract.read(
method,
parameters: [exploredAddress] as [AnyObject],
extraData: Data(),
transactionOptions: options)!
method,
parameters: [exploredAddress] as [AnyObject],
extraData: Data(),
transactionOptions: options)!
let tokenBalance = try! tx.call()
let balanceBigUInt = tokenBalance["0"] as! BigUInt
let balanceString = Web3.Utils.formatToEthereumUnits(balanceResult, toUnits: .eth, decimals: 3)!
Expand All @@ -264,10 +264,10 @@ options.from = walletAddress
options.gasPrice = .automatic
options.gasLimit = .automatic
let tx = contract.write(
"fallback",
parameters: [AnyObject](),
extraData: Data(),
transactionOptions: options)!
"fallback",
parameters: [AnyObject](),
extraData: Data(),
transactionOptions: options)!
```

##### Send ERC-20 Token
Expand All @@ -286,10 +286,10 @@ options.gasPrice = .automatic
options.gasLimit = .automatic
let method = "transfer"
let tx = contract.write(
method,
parameters: [toAddress, amount] as [AnyObject],
extraData: Data(),
transactionOptions: options)!
method,
parameters: [toAddress, amount] as [AnyObject],
extraData: Data(),
transactionOptions: options)!
```

##### Write Transaction and call smart contract method
Expand All @@ -311,10 +311,10 @@ options.from = walletAddress
options.gasPrice = .automatic
options.gasLimit = .automatic
let tx = contract.write(
contractMethod,
parameters: parameters,
extraData: extraData,
transactionOptions: options)!
contractMethod,
parameters: parameters,
extraData: extraData,
transactionOptions: options)!
```

##### Read Transaction to call smart contract method
Expand All @@ -333,10 +333,10 @@ options.from = walletAddress
options.gasPrice = .automatic
options.gasLimit = .automatic
let tx = contract.read(
contractMethod,
parameters: parameters,
extraData: extraData,
transactionOptions: options)!
contractMethod,
parameters: parameters,
extraData: extraData,
transactionOptions: options)!
```

#### Send Transaction
Expand Down Expand Up @@ -366,17 +366,17 @@ let blockNumber = try! web3.eth.getBlockNumber()

### Web3socketDelegate

To receive messages from endpoint you need to create a class that adopt to Web3SocketDelegate protocol.
Later, in order to open a connection to WebSocket server, you will use socket provider (WebsocketProvider or InfuraWebsocketProvider). And we recommend you to make it a property, so it doesn't get deallocated right after being setup.
To receive messages from endpoint you need to create a class that adopts to Web3SocketDelegate protocol.
Later, to open a connection to WebSocket server, you will use socket provider (`WebsocketProvider` or `InfuraWebsocketProvider`). And we recommend you to make it a property, so it doesn't get deallocated right after being setup.
```swift
class DelegateClass: Web3SocketDelegate {
var socketProvider: WebsocketProvider? = nil // WebSocket Provider
var socketProvider: InfuraWebsocketProvider? = nil // Infura WebSocket Provider
var socketProvider: WebsocketProvider? = nil // WebSocket Provider
var socketProvider: InfuraWebsocketProvider? = nil // Infura WebSocket Provider

// Protocol method, here will be messages, received from WebSocket server
func received(message: Any) {
// Make something with message
}
// Protocol method, here will be messages, received from WebSocket server
func received(message: Any) {
// Make something with message
}
}
```

Expand Down
Loading

0 comments on commit 515f80e

Please sign in to comment.