Skip to content

Commit 9bb3355

Browse files
committed
README improvements
1 parent e070c5a commit 9bb3355

File tree

5 files changed

+72
-24
lines changed

5 files changed

+72
-24
lines changed

Diff for: README.md

+63-10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
[Etherscan](https://etherscan.io/apis) Java API implementation.
44

5+
Library supports all available EtherScan *API* calls for all available *Ethereum Networks*.
56

67
![](https://media.giphy.com/media/1msHfmVdtuwkXww4ZC/giphy.gif)
78

@@ -34,55 +35,107 @@ dependencies {
3435
- [Transactions](#transaction-api)
3536
- [Version History](#version-history)
3637

37-
## Overall
38-
39-
How all is linked together:
40-
4138
## Api Examples
4239

4340
You can read about all API methods on [Etherscan](https://etherscan.io/apis)
4441

45-
You can you API with you key or without key as well.
42+
*Library support all available EtherScan API.*
43+
44+
You can use API with you key or without key as well (Check API request\sec restrictions).
4645
```java
4746
EtherScanApi api = new EtherScanApi();
4847
EtherScanApi api = new EtherScanApi("YourApiKey");
4948
```
5049

50+
Below there are examples for each API category.
51+
5152
### Mainnet and Testnets
52-
API support: *MAINNET, ROPSTEN, KOVAN, RINKEBY* networks.
53+
API support Ethereum: *[MAINNET](https://etherscan.io), [ROPSTEN](https://ropsten.etherscan.io), [KOVAN](https://kovan.etherscan.io), [RINKEBY](https://rinkeby.etherscan.io)* networks.
5354
```java
5455
EtherScanApi api = new EtherScanApi(EthNetwork.MAINNET);
5556
EtherScanApi api = new EtherScanApi("YourApiKey", EthNetwork.KOVAN);
5657
```
5758

5859
### Account Api
59-
**Get Ether Balance for a single Address Example**
60+
**Get Ether Balance for a single Address**
6061
```java
6162
EtherScanApi api = new EtherScanApi();
6263
Balance balance = api.account().balance("0x8d4426f94e42f721C7116E81d6688cd935cB3b4F");
6364
```
6465

6566
### Block Api
67+
**Get uncles block for block height**
68+
```java
69+
EtherScanApi api = new EtherScanApi();
70+
Optional<UncleBlock> uncles = api.block().uncles(200000);
71+
```
6672

6773
### Contract Api
74+
**Request contract ABI from [verified codes](https://etherscan.io/contractsVerified)**
75+
```java
76+
EtherScanApi api = new EtherScanApi();
77+
Abi abi = api.contract().contractAbi("0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413");
78+
```
6879

6980
### Logs Api
81+
**Get event logs for single topic**
82+
```java
83+
EtherScanApi api = new EtherScanApi();
84+
LogQuery query = LogQueryBuilder.with("0x33990122638b9132ca29c723bdf037f1a891a70c")
85+
.topic("0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545")
86+
.build();
87+
List<Log> logs = api.logs().logs(query);
88+
```
89+
90+
**Get event logs for 3 topics with respectful operations**
91+
```java
92+
EtherScanApi api = new EtherScanApi();
93+
LogQuery query = LogQueryBuilder.with("0x33990122638b9132ca29c723bdf037f1a891a70c", 379224, 400000)
94+
.topic("0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545",
95+
"0x72657075746174696f6e00000000000000000000000000000000000000000000",
96+
"0x72657075746174696f6e00000000000000000000000000000000000000000000")
97+
.setOpTopic0_1(LogOp.AND)
98+
.setOpTopic0_2(LogOp.OR)
99+
.setOpTopic1_2(LogOp.AND)
100+
.build();
101+
List<Log> logs = api.logs().logs(query);
102+
```
70103

71104
### Proxy Api
105+
**Get tx detailds with proxy endpoint**
106+
```java
107+
EtherScanApi api = new EtherScanApi(EthNetwork.MAINNET);
108+
Optional<TxProxy> tx = api.proxy().tx("0x1e2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1");
109+
```
110+
111+
**Get block info with proxy endpoint**
112+
```java
113+
EtherScanApi api = new EtherScanApi(EthNetwork.MAINNET);
114+
Optional<BlockProxy> block = api.proxy().block(15215);
115+
```
72116

73117
### Stats Api
118+
**Statistic about last price**
119+
```java
120+
EtherScanApi api = new EtherScanApi();
121+
Price price = api.stats().lastPrice();
122+
```
74123

75124
### Transaction Api
76-
125+
**Request receipt status for tx**
126+
```java
127+
EtherScanApi api = new EtherScanApi();
128+
Optional<Boolean> status = api.txs().receiptStatus("0x513c1ba0bebf66436b5fed86ab668452b7805593c05073eb2d51d3a52f480a76");
129+
```
77130

78131
### Token Api
79132
You can read account API [here](https://etherscan.io/apis#accounts)
80133

81-
Token API migrated to account & stats respectfully.
134+
Token API methods migrated to [Account](#account-api) & [Stats](#stats-api) respectfully.
82135

83136
## Version History
84137

85-
**1.0.0** - Initial project with all API functionality.
138+
**1.0.0** - Initial project with all API functionality, for all available networks, with tests coverage for all cases.
86139

87140
## License
88141

Diff for: src/main/java/io/api/etherscan/App.java

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
package io.api.etherscan;
22

3-
import io.api.etherscan.core.impl.EtherScanApi;
4-
import io.api.etherscan.model.Balance;
5-
import io.api.etherscan.model.EthNetwork;
6-
7-
/**
8-
*
9-
*/
103
public class App {
114
public static void main(String[] args) {
12-
EtherScanApi api = new EtherScanApi(EthNetwork.MAINNET);
13-
Balance balance = api.account().balance("0x8d4426f94e42f721C7116E81d6688cd935cB3b4F");
14-
System.out.println("Test");
5+
156
}
167
}

Diff for: src/main/java/io/api/etherscan/core/impl/EtherScanApi.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.api.etherscan.core.impl;
22

33
import io.api.etherscan.core.*;
4+
import io.api.etherscan.error.ApiException;
45
import io.api.etherscan.error.ApiKeyException;
56
import io.api.etherscan.executor.IHttpExecutor;
67
import io.api.etherscan.executor.impl.HttpExecutor;
@@ -54,14 +55,16 @@ public EtherScanApi(final String apiKey,
5455
if (BasicUtils.isBlank(apiKey))
5556
throw new ApiKeyException("API key can not be null or empty");
5657

58+
if(network == null)
59+
throw new ApiException("Ethereum Network is set to NULL value");
60+
5761
// EtherScan 5request\sec limit support by queue manager
5862
final IQueueManager masterQueue = (apiKey.equals("YourApiKeyToken"))
5963
? new FakeQueueManager()
6064
: new QueueManager(5, 1);
6165

6266
final IHttpExecutor executor = executorSupplier.get();
63-
final EthNetwork usedNetwork = (network == null) ? EthNetwork.MAINNET : network;
64-
final String baseUrl = "https://" + usedNetwork.getDomain() + ".etherscan.io/api" + "?apikey=" + apiKey;
67+
final String baseUrl = "https://" + network.getDomain() + ".etherscan.io/api" + "?apikey=" + apiKey;
6568

6669
this.account = new AccountApiProvider(masterQueue, baseUrl, executor);
6770
this.block = new BlockApiProvider(masterQueue, baseUrl, executor);

Diff for: src/main/java/io/api/etherscan/executor/impl/HttpExecutor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ private String readData(final HttpURLConnection connection) throws IOException {
127127
}
128128

129129
private InputStreamReader getStreamReader(final HttpURLConnection connection) throws IOException {
130-
return ("gzip".equals(connection.getContentEncoding()))
130+
return (connection.getContentEncoding() != null && "gzip".equals(connection.getContentEncoding()))
131131
? new InputStreamReader(new GZIPInputStream(connection.getInputStream()), "utf-8")
132132
: new InputStreamReader(connection.getInputStream(), "utf-8");
133133
}

Diff for: src/test/java/io/api/etherscan/EtherScanApiTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.api.etherscan;
22

33
import io.api.etherscan.core.impl.EtherScanApi;
4+
import io.api.etherscan.error.ApiException;
45
import io.api.etherscan.error.ApiKeyException;
56
import io.api.etherscan.model.EthNetwork;
67
import org.junit.Assert;
@@ -35,7 +36,7 @@ public void blankKey() {
3536
EtherScanApi api = new EtherScanApi(blankKey, network);
3637
}
3738

38-
@Test
39+
@Test(expected = ApiException.class)
3940
public void nullNetwork() {
4041
EtherScanApi api = new EtherScanApi(validKey, null);
4142
assertNotNull(api);

0 commit comments

Comments
 (0)