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
6268In 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
9093Below 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 = new EtherScanApi ();
99+ EtherScanAPI api = EtherScanAPI . build ();
98100Balance 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 = new EtherScanApi ();
107+ EtherScanAPI api = EtherScanAPI . build ();
107108Optional<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 = new EtherScanApi ();
114+ EtherScanAPI api = EtherScanAPI . build ();
114115Abi 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 = 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" )
125125 .build();
126126List<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
142143List<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 = new EtherScanApi ( EthNetwork . MAINNET );
150+ EtherScanAPI api = EtherScanAPI . build( );
151151Optional<TxProxy > tx = api. proxy(). tx(" 0x1e2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1" );
152152```
153153
154154** Get block info with proxy endpoint**
155-
156155``` java
157- EtherScanApi api = new EtherScanApi ( EthNetwork . MAINNET );
156+ EtherScanAPI api = EtherScanAPI . build( );
158157Optional<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 = new EtherScanApi ();
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 = new EtherScanApi ();
172+ EtherScanAPI api = EtherScanAPI . build ();
176173Optional<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
183180Token API methods migrated to [ Account] ( #account-api ) & [ Stats] ( #stats-api ) respectfully.
184181
0 commit comments