Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fdf0f98

Browse files
Merge pull request #25 from GoodforGod/dev
[2.0.0]
2 parents cafcdff + c64a301 commit fdf0f98

File tree

218 files changed

+8559
-5581
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

218 files changed

+8559
-5581
lines changed

β€Ž.editorconfig

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,30 @@ root = true
88
end_of_line = lf
99
charset = utf-8
1010

11+
# Json
12+
[*.json]
13+
indent_size = 2
14+
indent_style = space
15+
insert_final_newline = false
16+
trim_trailing_whitespace = true
17+
1118
# Yaml
1219
[{*.yml, *.yaml}]
1320
indent_size = 2
1421
indent_style = space
22+
insert_final_newline = true
23+
trim_trailing_whitespace = true
1524

1625
# Property files
1726
[*.properties]
1827
indent_size = 2
1928
indent_style = space
29+
insert_final_newline = true
30+
trim_trailing_whitespace = true
2031

21-
32+
# XML files
33+
[*.xml]
34+
indent_size = 4
35+
indent_style = space
36+
insert_final_newline = true
37+
trim_trailing_whitespace = true

β€Ž.gitattributes

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
# and leave all files detected as binary untouched.
33
* text=auto
44

5-
#
5+
66
# The above will handle all files NOT found below
7-
#
87
# These files are text and should be normalized (Convert crlf => lf)
98
*.bash text eol=lf
109
*.css text diff=css
@@ -26,16 +25,36 @@
2625
*.xml text
2726
*.yml text eol=lf
2827

28+
2929
# These files are binary and should be left untouched
3030
# (binary is a macro for -text -diff)
31-
*.class binary
31+
# Archives
32+
*.7z binary
33+
*.br binary
34+
*.gz binary
35+
*.tar binary
36+
*.zip binary
37+
*.jar binary
38+
*.so binary
39+
*.war binary
3240
*.dll binary
33-
*.ear binary
34-
*.gif binary
41+
42+
# Documents
43+
*.pdf binary
44+
45+
# Images
3546
*.ico binary
36-
*.jar binary
47+
*.gif binary
3748
*.jpg binary
3849
*.jpeg binary
3950
*.png binary
40-
*.so binary
41-
*.war binary
51+
*.psd binary
52+
*.webp binary
53+
54+
# Fonts
55+
*.woff2 binary
56+
57+
# Other
58+
*.exe binary
59+
*.class binary
60+
*.ear binary

β€Ž.github/workflows/gradle.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest
1515
strategy:
1616
matrix:
17-
java: [ '11' ]
17+
java: [ '11', '17' ]
1818
name: Java ${{ matrix.java }} setup
1919

2020
steps:
@@ -32,11 +32,19 @@ jobs:
3232
run: ./gradlew spotlessCheck
3333

3434
- name: Test
35+
if: matrix.java == '11'
3536
run: ./gradlew test jacocoTestReport
3637
env:
37-
API_KEY: ${{ secrets.API_KEY }}
38+
ETHERSCAN_API_KEY: ${{ secrets.ETHERSCAN_API_KEY_1 }}
39+
40+
- name: Test
41+
if: matrix.java == '17'
42+
run: ./gradlew test jacocoTestReport
43+
env:
44+
ETHERSCAN_API_KEY: ${{ secrets.ETHERSCAN_API_KEY_2 }}
3845

3946
- name: SonarQube
47+
if: matrix.java == '17'
4048
run: ./gradlew sonarqube
4149
env:
4250
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

β€Ž.gitignore

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1-
/.settings/
2-
.idea
3-
.idea/httpRequests
4-
*.iml
1+
### Package Files
2+
*.war
3+
*.nar
4+
*.ear
5+
*.zip
6+
*.tar.gz
7+
*.rar
8+
9+
### Gradle template
510
.gradle
6-
build
11+
build/
712
target/
13+
14+
### Idea generated files
15+
.idea
16+
.settings/
17+
*.iml
18+
out/

β€ŽREADME.md

Lines changed: 64 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
11
# Java EtherScan API
22

3+
[![Minimum required Java version](https://img.shields.io/badge/Java-1.8%2B-blue?logo=openjdk)](https://openjdk.org/projects/jdk8/)
34
[![GitHub Action](https://github.com/goodforgod/java-etherscan-api/workflows/Java%20CI/badge.svg)](https://github.com/GoodforGod/java-etherscan-api/actions?query=workflow%3A%22Java+CI%22)
45
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_java-etherscan-api&metric=coverage)](https://sonarcloud.io/dashboard?id=GoodforGod_java-etherscan-api)
56
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_java-etherscan-api&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=GoodforGod_java-etherscan-api)
67
[![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_java-etherscan-api&metric=ncloc)](https://sonarcloud.io/dashboard?id=GoodforGod_java-etherscan-api)
7-
[![](https://jitpack.io/v/GoodforGod/java-etherscan-api.svg)](https://jitpack.io/#GoodforGod/java-etherscan-api)
88

9-
[Etherscan.io](https://etherscan.io/apis) Java API implementation.
9+
[Etherscan.io](https://docs.etherscan.io/) Java API implementation.
1010

11-
Library supports all available EtherScan *API* calls for all available *Ethereum Networks* for *etherscan.io*
11+
Library supports EtherScan *API* for all available *Ethereum Networks* for *etherscan.io*
1212

1313
## Dependency :rocket:
1414

1515
**Gradle**
1616
```groovy
17-
dependencies {
18-
compile "com.github.goodforgod:java-etherscan-api:1.2.1"
19-
}
17+
implementation "com.github.goodforgod:java-etherscan-api:2.0.0"
2018
```
2119

2220
**Maven**
2321
```xml
2422
<dependency>
2523
<groupId>com.github.goodforgod</groupId>
2624
<artifactId>java-etherscan-api</artifactId>
27-
<version>1.2.1</version>
25+
<version>2.0.0</version>
2826
</dependency>
2927
```
3028

@@ -42,143 +40,142 @@ dependencies {
4240
- [Token](#token-api)
4341
- [Version History](#version-history)
4442

45-
## Mainnet and Testnets
43+
## MainNet and TestNets
44+
45+
API support all Ethereum [default networks](https://docs.etherscan.io/getting-started/endpoint-urls):
46+
- [Mainnet](https://api.etherscan.io/)
47+
- [Goerli](https://api-goerli.etherscan.io/)
48+
- [Sepolia](https://api-sepolia.etherscan.io/)
4649

47-
API support Ethereum: *[MAINNET](https://etherscan.io),
48-
[ROPSTEN](https://ropsten.etherscan.io),
49-
[KOVAN](https://kovan.etherscan.io),
50-
[RINKEBY](https://rinkeby.etherscan.io),
51-
[GORLI](https://goerli.etherscan.io),
52-
[TOBALABA](https://tobalaba.etherscan.com)* networks.
5350
```java
54-
EtherScanApi api = new EtherScanApi(EthNetwork.MAINNET); // Default
55-
EtherScanApi apiRinkeby = new EtherScanApi(EthNetwork.RINKEBY);
56-
EtherScanApi apiRopsten = new EtherScanApi(EthNetwork.ROPSTEN);
57-
EtherScanApi apiKovan = new EtherScanApi("YourApiKey", EthNetwork.KOVAN);
51+
EtherScanAPI api = EtherScanAPI.build();
52+
EtherScanAPI apiGoerli = EtherScanAPI.builder().withNetwork(EthNetworks.GORLI).build();
53+
EtherScanAPI apiSepolia = EtherScanAPI.builder().withNetwork(EthNetworks.SEPOLIA).build();
54+
```
55+
56+
### Custom Network
57+
58+
In case you want to use API for other EtherScan compatible network, you can easily provide custom network with domain api URI.
59+
60+
```java
61+
EtherScanAPI api = EtherScanAPI.builder()
62+
.withNetwork(() -> URI.create("https://api-my-custom.etherscan.io/api"))
63+
.build();
5864
```
5965

6066
## Custom HttpClient
6167

6268
In case you need to set custom timeout, custom headers or better implementation for HttpClient,
63-
just implement **IHttpExecutor** by your self or initialize it with your values.
69+
just implement **EthHttpClient** by your self or initialize it with your values.
6470

6571
```java
66-
int connectionTimeout = 10000;
67-
int readTimeout = 7000;
68-
69-
Supplier<IHttpExecutor> supplier = () -> new HttpExecutor(connectionTimeout);
70-
Supplier<IHttpExecutor> supplierFull = () -> new HttpExecutor(connectionTimeout, readTimeout);
71-
72-
EtherScanApi api = new EtherScanApi(EthNetwork.RINKEBY, supplier);
73-
EtherScanApi apiWithKey = new EtherScanApi("YourApiKey", EthNetwork.MAINNET, supplierFull);
72+
Supplier<EthHttpClient> ethHttpClientSupplier = () -> new UrlEthHttpClient(Duration.ofMillis(300), Duration.ofMillis(300));
73+
EtherScanAPI api = EtherScanAPI.builder()
74+
.withHttpClient(supplier)
75+
.build();
7476
```
7577

7678
## API Examples
7779

78-
You can read about all API methods on [Etherscan](https://etherscan.io/apis)
80+
You can read about all API methods on [Etherscan](https://docs.etherscan.io/api-endpoints/accounts)
7981

8082
*Library support all available EtherScan API.*
8183

82-
You can use library *with or without* API key *([Check API request\sec restrictions when used without API key](https://ethereum.stackexchange.com/questions/34190/does-etherscan-require-the-use-of-an-api-key))*.
84+
You can use library *with or without* API key *([Check API request\sec restrictions when used without API key](https://docs.etherscan.io/getting-started/viewing-api-usage-statistics))*.
8385

84-
Library will automatically limit requests up to **5 req/sec** when used *without* key.
86+
Library will automatically limit requests up to **1 requests in 5 seconds** when used *without* key and up to **5 requests in 1 seconds** when used with API KEY (free plan).
8587
```java
86-
EtherScanApi api = new EtherScanApi();
87-
EtherScanApi api = new EtherScanApi("YourApiKey");
88+
EtherScanAPI.builder()
89+
.withApiKey(ApiRunner.API_KEY)
90+
.build();
8891
```
8992

9093
Below are examples for each API category.
9194

92-
### Account Api
95+
### Account API
9396

9497
**Get Ether Balance for a single Address**
95-
9698
```java
97-
EtherScanApi api = newEtherScanApi();
99+
EtherScanAPI api = EtherScanAPI.build();
98100
Balance balance = api.account().balance("0x8d4426f94e42f721C7116E81d6688cd935cB3b4F");
99101
```
100102

101-
### Block Api
103+
### Block API
102104

103105
**Get uncles block for block height**
104-
105106
```java
106-
EtherScanApi api = newEtherScanApi();
107+
EtherScanAPI api = EtherScanAPI.build();
107108
Optional<UncleBlock> uncles = api.block().uncles(200000);
108109
```
109110

110-
### Contract Api
111+
### Contract API
111112
**Request contract ABI from [verified codes](https://etherscan.io/contractsVerified)**
112113
```java
113-
EtherScanApi api = newEtherScanApi();
114+
EtherScanAPI api = EtherScanAPI.build();
114115
Abi abi = api.contract().contractAbi("0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413");
115116
```
116117

117-
### Logs Api
118+
### Logs API
118119

119120
**Get event logs for single topic**
120-
121121
```java
122-
EtherScanApi api = newEtherScanApi();
123-
LogQuery query = LogQueryBuilder.with("0x33990122638b9132ca29c723bdf037f1a891a70c")
124-
.topic("0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545")
122+
EtherScanAPI api = EtherScanAPI.build();
123+
LogQuery query = LogQuery.builder("0x33990122638b9132ca29c723bdf037f1a891a70c")
124+
.withTopic("0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545")
125125
.build();
126126
List<Log> logs = api.logs().logs(query);
127127
```
128128

129129
**Get event logs for 3 topics with respectful operations**
130-
131130
```java
132-
EtherScanApi api = new EtherScanApi();
133-
LogQuery query = LogQueryBuilder.with("0x33990122638b9132ca29c723bdf037f1a891a70c", 379224, 400000)
134-
.topic("0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545",
135-
"0x72657075746174696f6e00000000000000000000000000000000000000000000",
136-
"0x72657075746174696f6e00000000000000000000000000000000000000000000")
131+
EtherScanAPI api = EtherScanAPI.build();
132+
LogQuery query = LogQuery.builder("0x33990122638b9132ca29c723bdf037f1a891a70c")
133+
.withBlockFrom(379224)
134+
.withBlockTo(400000)
135+
.withTopic("0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545",
136+
"0x72657075746174696f6e00000000000000000000000000000000000000000000",
137+
"0x72657075746174696f6e00000000000000000000000000000000000000000000")
137138
.setOpTopic0_1(LogOp.AND)
138-
.setOpTopic0_2(LogOp.OR)
139+
.setOpTopic0_2(null)
139140
.setOpTopic1_2(LogOp.AND)
140141
.build();
141142

142143
List<Log> logs = api.logs().logs(query);
143144
```
144145

145-
### Proxy Api
146-
147-
**Get tx detailds with proxy endpoint**
146+
### Proxy API
148147

148+
**Get tx details with proxy endpoint**
149149
```java
150-
EtherScanApi api = newEtherScanApi(EthNetwork.MAINNET);
150+
EtherScanAPI api = EtherScanAPI.build();
151151
Optional<TxProxy> tx = api.proxy().tx("0x1e2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1");
152152
```
153153

154154
**Get block info with proxy endpoint**
155-
156155
```java
157-
EtherScanApi api = newEtherScanApi(EthNetwork.MAINNET);
156+
EtherScanAPI api = EtherScanAPI.build();
158157
Optional<BlockProxy> block = api.proxy().block(15215);
159158
```
160159

161-
### Stats Api
160+
### Stats API
162161

163162
**Statistic about last price**
164-
165163
```java
166-
EtherScanApi api = newEtherScanApi();
167-
Price price = api.stats().lastPrice();
164+
EtherScanAPI api = EtherScanAPI.build();
165+
Price price = api.stats().priceLast();
168166
```
169167

170-
### Transaction Api
168+
### Transaction API
171169

172170
**Request receipt status for tx**
173-
174171
```java
175-
EtherScanApi api = newEtherScanApi();
172+
EtherScanAPI api = EtherScanAPI.build();
176173
Optional<Boolean> status = api.txs().receiptStatus("0x513c1ba0bebf66436b5fed86ab668452b7805593c05073eb2d51d3a52f480a76");
177174
```
178175

179-
### Token Api
176+
### Token API
180177

181-
You can read about token API [here](https://etherscan.io/apis#tokens)
178+
You can read about token API [here](https://docs.etherscan.io/api-endpoints/tokens)
182179

183180
Token API methods migrated to [Account](#account-api) & [Stats](#stats-api) respectfully.
184181

0 commit comments

Comments
(0)

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /