1
1
# Java EtherScan API
2
2
3
+ [ ![ Minimum required Java version] ( https://img.shields.io/badge/Java-1.8%2B-blue?logo=openjdk )] ( https://openjdk.org/projects/jdk8/ )
3
4
[ ![ 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 )
4
5
[ ![ Coverage] ( https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_java-etherscan-api&metric=coverage )] ( https://sonarcloud.io/dashboard?id=GoodforGod_java-etherscan-api )
5
6
[ ![ 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 )
6
7
[ ![ 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 )
8
8
9
- [ Etherscan.io] ( https://etherscan.io/apis ) Java API implementation.
9
+ [ Etherscan.io] ( https://docs. etherscan.io/ ) Java API implementation.
10
10
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*
12
12
13
13
## Dependency :rocket :
14
14
15
15
** Gradle**
16
16
``` 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"
20
18
```
21
19
22
20
** Maven**
23
21
``` xml
24
22
<dependency >
25
23
<groupId >com.github.goodforgod</groupId >
26
24
<artifactId >java-etherscan-api</artifactId >
27
- <version >1.2.1 </version >
25
+ <version >2.0.0 </version >
28
26
</dependency >
29
27
```
30
28
@@ -42,143 +40,142 @@ dependencies {
42
40
- [ Token] ( #token-api )
43
41
- [ Version History] ( #version-history )
44
42
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/ )
46
49
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.
53
50
``` 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();
58
64
```
59
65
60
66
## Custom HttpClient
61
67
62
68
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.
64
70
65
71
``` 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();
74
76
```
75
77
76
78
## API Examples
77
79
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 )
79
81
80
82
* Library support all available EtherScan API.*
81
83
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 ) )* .
83
85
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) .
85
87
``` java
86
- EtherScanApi api = new EtherScanApi ();
87
- EtherScanApi api = new EtherScanApi (" YourApiKey" );
88
+ EtherScanAPI . builder()
89
+ .withApiKey(ApiRunner . API_KEY )
90
+ .build();
88
91
```
89
92
90
93
Below are examples for each API category.
91
94
92
- ### Account Api
95
+ ### Account API
93
96
94
97
** Get Ether Balance for a single Address**
95
-
96
98
``` java
97
- EtherScanApi api = new EtherScanApi ();
99
+ EtherScanAPI api = EtherScanAPI . build ();
98
100
Balance balance = api. account(). balance(" 0x8d4426f94e42f721C7116E81d6688cd935cB3b4F" );
99
101
```
100
102
101
- ### Block Api
103
+ ### Block API
102
104
103
105
** Get uncles block for block height**
104
-
105
106
``` java
106
- EtherScanApi api = new EtherScanApi ();
107
+ EtherScanAPI api = EtherScanAPI . build ();
107
108
Optional<UncleBlock > uncles = api. block(). uncles(200000 );
108
109
```
109
110
110
- ### Contract Api
111
+ ### Contract API
111
112
** Request contract ABI from [ verified codes] ( https://etherscan.io/contractsVerified ) **
112
113
``` java
113
- EtherScanApi api = new EtherScanApi ();
114
+ EtherScanAPI api = EtherScanAPI . build ();
114
115
Abi abi = api. contract(). contractAbi(" 0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413" );
115
116
```
116
117
117
- ### Logs Api
118
+ ### Logs API
118
119
119
120
** Get event logs for single topic**
120
-
121
121
``` java
122
- EtherScanApi api = new EtherScanApi ();
123
- LogQuery query = LogQueryBuilder . with (" 0x33990122638b9132ca29c723bdf037f1a891a70c" )
124
- .topic (" 0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545" )
122
+ EtherScanAPI api = EtherScanAPI . build ();
123
+ LogQuery query = LogQuery . builder (" 0x33990122638b9132ca29c723bdf037f1a891a70c" )
124
+ .withTopic (" 0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545" )
125
125
.build();
126
126
List<Log > logs = api. logs(). logs(query);
127
127
```
128
128
129
129
** Get event logs for 3 topics with respectful operations**
130
-
131
130
``` 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" )
137
138
.setOpTopic0_1(LogOp . AND )
138
- .setOpTopic0_2(LogOp . OR )
139
+ .setOpTopic0_2(null )
139
140
.setOpTopic1_2(LogOp . AND )
140
141
.build();
141
142
142
143
List<Log > logs = api. logs(). logs(query);
143
144
```
144
145
145
- ### Proxy Api
146
-
147
- ** Get tx detailds with proxy endpoint**
146
+ ### Proxy API
148
147
148
+ ** Get tx details with proxy endpoint**
149
149
``` java
150
- EtherScanApi api = new EtherScanApi ( EthNetwork . MAINNET );
150
+ EtherScanAPI api = EtherScanAPI . build( );
151
151
Optional<TxProxy > tx = api. proxy(). tx(" 0x1e2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1" );
152
152
```
153
153
154
154
** Get block info with proxy endpoint**
155
-
156
155
``` java
157
- EtherScanApi api = new EtherScanApi ( EthNetwork . MAINNET );
156
+ EtherScanAPI api = EtherScanAPI . build( );
158
157
Optional<BlockProxy > block = api. proxy(). block(15215 );
159
158
```
160
159
161
- ### Stats Api
160
+ ### Stats API
162
161
163
162
** Statistic about last price**
164
-
165
163
``` java
166
- EtherScanApi api = new EtherScanApi ();
167
- Price price = api. stats(). lastPrice ();
164
+ EtherScanAPI api = EtherScanAPI . build ();
165
+ Price price = api. stats(). priceLast ();
168
166
```
169
167
170
- ### Transaction Api
168
+ ### Transaction API
171
169
172
170
** Request receipt status for tx**
173
-
174
171
``` java
175
- EtherScanApi api = new EtherScanApi ();
172
+ EtherScanAPI api = EtherScanAPI . build ();
176
173
Optional<Boolean > status = api. txs(). receiptStatus(" 0x513c1ba0bebf66436b5fed86ab668452b7805593c05073eb2d51d3a52f480a76" );
177
174
```
178
175
179
- ### Token Api
176
+ ### Token API
180
177
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 )
182
179
183
180
Token API methods migrated to [ Account] ( #account-api ) & [ Stats] ( #stats-api ) respectfully.
184
181
0 commit comments