|
| 1 | +# Getting Started with CryptoScraper |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +### Library Initialization |
| 6 | + |
| 7 | +#### Scanner Configuration |
| 8 | + |
| 9 | +To initialize the library, first the scanners that you would like to use must be configured with your API keys. You can specify the API keys via the Swift Environment, or directly through ``EthereumScanner``.apiKey |
| 10 | + |
| 11 | +```swift |
| 12 | +Etherscan.apiKey = "<my Etherscan API key>" |
| 13 | +PolygonScan.apiKey = "<my PolygonScan API key>" |
| 14 | +``` |
| 15 | + |
| 16 | +#### Crypto Data Aggregator Configuration |
| 17 | + |
| 18 | +Once all needed scanners have been configured, a ``CryptoDataAggregator``'s API key must be specified. Again, this can be specified via the Swift Environment, or directly through the aggregator's properties: |
| 19 | + |
| 20 | +```swift |
| 21 | +CoinGeckoAggregator.apiKey = "<my CoinGecko API key>" |
| 22 | +``` |
| 23 | + |
| 24 | +#### Initialize the Library |
| 25 | + |
| 26 | +The final initialization step is to initialize the library. This will perform a one-time load of token infromation via the ``CryptoDataAggregator``. |
| 27 | + |
| 28 | +```swift |
| 29 | +try await CryptoScraper.initialize() |
| 30 | +``` |
| 31 | + |
| 32 | +### Retrieving Information from Ethereum-based Scanners |
| 33 | + |
| 34 | +#### Retrieving the balance for an account |
| 35 | + |
| 36 | +The ``EthereumScanner`` protocol can be used to retrieve information for accounts and contracts. To retrieve the balance for a particular account (address): |
| 37 | + |
| 38 | +```swift |
| 39 | +let etherScan = Etherscan() |
| 40 | +let balance = try await etherScan.getBalance(forAccount: accountContract) |
| 41 | +``` |
| 42 | + |
| 43 | +The balance will be in ``CryptoAmount``. See the documentation on that protocol for more information. |
| 44 | + |
| 45 | +#### Retrieving the balance of a particular coin for an account |
| 46 | + |
| 47 | +To retrieve the balance of a coin for a particular account (address): |
| 48 | + |
| 49 | +```swift |
| 50 | +let etherScan = Etherscan() |
| 51 | +let rlcToken = EthereumContract(address: "0x607F4C5BB672230e8672085532f7e901544a7375") |
| 52 | +let balance = try await etherScan.getBalance(forToken: rlcToken, forAccount: accountContract) |
| 53 | +``` |
| 54 | + |
| 55 | +### Retrieving the transactions for an account |
| 56 | + |
| 57 | +To retrieve the transactions for a particular account (address): |
| 58 | + |
| 59 | +```swift |
| 60 | +let etherScan = Etherscan() |
| 61 | +let transactions = try await etherScan.getTransactions(forAccount: accountContract) |
| 62 | +``` |
0 commit comments