Skip to content

Commit

Permalink
add getting started get transactions section
Browse files Browse the repository at this point in the history
  • Loading branch information
yuzushioh committed Mar 10, 2018
1 parent 7021269 commit 63d9c33
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
12 changes: 12 additions & 0 deletions Documentation/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ do {

## Geth
`Geth` is responsible for interacting with Ethereum network. Geth interacts with network via JSONRPC. You can see the list of JSONRPC requests [here](Documentation/JSONRPC.md).
To create `Configuration` struct for `Geth`, you need
- url for Ethereum node. you can get one at [infura.io](https://infura.io)
- Etherscan API key. you can get one at [Etherscan](https://etherscan.io)

```swift
// Create an instance of `Geth` with `Configuration`.
Expand All @@ -75,6 +78,15 @@ geth.getBalance(of: address, blockParameter: .latest) { result in

```

### Get Transactions
To get the list of transactions related to the specified address, `Geth` uses Etherscan API.

```swift
geth.getTransactions(address: address) { result in
// Do something
}
```

### Send Ether
You need to create `RawTransaction` with
- value (how much ether/wei you want to send)
Expand Down
4 changes: 2 additions & 2 deletions EthereumKit/Networking/Geth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public final class Geth {

// MARK: - Etherscan APIs

public func getTransactions(address: Address, handler: @escaping (Result<Transactions, GethError>) -> Void) {
etherscanClient.send(Etherscan.GetTransactions(address: address), handler: handler)
public func getTransactions(address: String, handler: @escaping (Result<Transactions, GethError>) -> Void) {
etherscanClient.send(Etherscan.GetTransactions(address: Address(string: address)), handler: handler)
}
}
4 changes: 4 additions & 0 deletions Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ class ViewController: UIViewController {
// Do something
}

geth.getTransactions(address: address) { result in
print(result)
}

// You can get the current nonce by calling
geth.getTransactionCount(of: address) { result in
switch result {
Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@ EthereumKit is a Swift framework that enables you to create Ethereum wallet and

```swift
// BIP39: Generate seed and mnemonic sentence.

let mnemonic = Mnemonic.create()
let seed = Mnemonic.createSeed(mnemonic: mnemonic)

// BIP32: Key derivation and address generation
let wallet = try HDWallet(seed: seed, network: .main)
let address = try wallet.generateAddress(at: 0)

let wallet: Wallet
do {
wallet = try Wallet(seed: seed, network: .main)
} catch let error {
fatalError("Error: \(error.localizedDescription)")
}

// Send some ether
let rawTransaction = RawTransaction(ether: "0.15", address: "0x88b44BC83add758A3642130619D61682282850Df", nonce: 2)
let rawTransaction = RawTransaction(ether: "0.15", address: wallet.generateAddress(), nonce: 0)
let tx = try wallet.signTransaction(rawTransaction)

geth.sendRawTransaction(rawTransaction: tx) { result in
Expand Down

0 comments on commit 63d9c33

Please sign in to comment.