@@ -43,141 +43,140 @@ implementation "com.github.goodforgod:java-etherscan-api:2.0.0-SNAPSHOT"
43
43
44
44
## Mainnet and Testnets
45
45
46
- API support Ethereum: * [ MAINNET] ( https://etherscan.io ) ,
47
- [ ROPSTEN] ( https://ropsten.etherscan.io ) ,
48
- [ KOVAN] ( https://kovan.etherscan.io ) ,
49
- [ RINKEBY] ( https://rinkeby.etherscan.io ) ,
50
- [ GORLI] ( https://goerli.etherscan.io ) ,
51
- [ TOBALABA] ( https://tobalaba.etherscan.com ) * networks.
46
+ API support Ethereum [ default networks] ( https://docs.etherscan.io/getting-started/endpoint-urls ) :
47
+ - [ Mainnet] ( https://api.etherscan.io/ )
48
+ - [ Goerli] ( https://api-goerli.etherscan.io/ )
49
+ - [ Sepolia] ( https://api-sepolia.etherscan.io/ )
50
+
52
51
``` java
53
- EtherScanApi api = new EtherScanApi (EthNetwork . MAINNET ); // Default
54
- EtherScanApi apiRinkeby = new EtherScanApi (EthNetwork . RINKEBY );
55
- EtherScanApi apiRopsten = new EtherScanApi (EthNetwork . ROPSTEN );
56
- EtherScanApi apiKovan = new EtherScanApi (" YourApiKey" , EthNetwork . KOVAN );
52
+ EtherScanAPI api = EtherScanAPI . build();
53
+ EtherScanAPI apiGoerli = EtherScanAPI . builder(). withNetwork(EthNetworks . GORLI ). build();
54
+ EtherScanAPI apiSepolia = EtherScanAPI . builder(). withNetwork(EthNetworks . SEPOLIA ). build();
55
+ ```
56
+
57
+ ### Custom Network
58
+
59
+ In case you want to use API for other EtherScan compatible network, you can easily provide custom network with domain api URI.
60
+
61
+ ``` java
62
+ EtherScanAPI api = EtherScanAPI . builder()
63
+ .withNetwork(() - > URI . create(" https://api-my-custom.etherscan.io/api" ))
64
+ .build();
57
65
```
58
66
59
67
## Custom HttpClient
60
68
61
69
In case you need to set custom timeout, custom headers or better implementation for HttpClient,
62
- just implement ** IHttpExecutor ** by your self or initialize it with your values.
70
+ just implement ** EthHttpClient ** by your self or initialize it with your values.
63
71
64
72
``` java
65
- int connectionTimeout = 10000 ;
66
- int readTimeout = 7000 ;
67
-
68
- Supplier<IHttpExecutor > supplier = () - > new HttpExecutor (connectionTimeout);
69
- Supplier<IHttpExecutor > supplierFull = () - > new HttpExecutor (connectionTimeout, readTimeout);
70
-
71
- EtherScanApi api = new EtherScanApi (EthNetwork . RINKEBY , supplier);
72
- EtherScanApi apiWithKey = new EtherScanApi (" YourApiKey" , EthNetwork . MAINNET , supplierFull);
73
+ Supplier<EthHttpClient > ethHttpClientSupplier = () - > new UrlEthHttpClient (Duration . ofMillis(300 ), Duration . ofMillis(300 ));
74
+ EtherScanAPI api = EtherScanAPI . builder()
75
+ .withHttpClient(supplier)
76
+ .build();
73
77
```
74
78
75
79
## API Examples
76
80
77
- You can read about all API methods on [ Etherscan] ( https://etherscan.io/apis )
81
+ You can read about all API methods on [ Etherscan] ( https://docs. etherscan.io/api-endpoints/accounts )
78
82
79
83
* Library support all available EtherScan API.*
80
84
81
- 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 ) )* .
85
+ 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 ) )* .
82
86
83
- Library will automatically limit requests up to ** 5 req/sec ** when used * without* key.
87
+ 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) .
84
88
``` java
85
- EtherScanApi api = new EtherScanApi ();
86
- EtherScanApi api = new EtherScanApi (" YourApiKey" );
89
+ EtherScanAPI . builder()
90
+ .withApiKey(ApiRunner . API_KEY )
91
+ .build();
87
92
```
88
93
89
94
Below are examples for each API category.
90
95
91
- ### Account Api
96
+ ### Account API
92
97
93
98
** Get Ether Balance for a single Address**
94
-
95
99
``` java
96
- EtherScanApi api = new EtherScanApi ();
100
+ EtherScanAPI api = EtherScanAPI . build ();
97
101
Balance balance = api. account(). balance(" 0x8d4426f94e42f721C7116E81d6688cd935cB3b4F" );
98
102
```
99
103
100
- ### Block Api
104
+ ### Block API
101
105
102
106
** Get uncles block for block height**
103
-
104
107
``` java
105
- EtherScanApi api = new EtherScanApi ();
108
+ EtherScanAPI api = EtherScanAPI . build ();
106
109
Optional<UncleBlock > uncles = api. block(). uncles(200000 );
107
110
```
108
111
109
- ### Contract Api
112
+ ### Contract API
110
113
** Request contract ABI from [ verified codes] ( https://etherscan.io/contractsVerified ) **
111
114
``` java
112
- EtherScanApi api = new EtherScanApi ();
115
+ EtherScanAPI api = EtherScanAPI . build ();
113
116
Abi abi = api. contract(). contractAbi(" 0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413" );
114
117
```
115
118
116
- ### Logs Api
119
+ ### Logs API
117
120
118
121
** Get event logs for single topic**
119
-
120
122
``` java
121
- EtherScanApi api = new EtherScanApi ();
123
+ EtherScanAPI api = EtherScanAPI . build ();
122
124
LogQuery query = LogQueryBuilder . with(" 0x33990122638b9132ca29c723bdf037f1a891a70c" )
123
125
.topic(" 0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545" )
124
126
.build();
125
127
List<Log > logs = api. logs(). logs(query);
126
128
```
127
129
128
130
** Get event logs for 3 topics with respectful operations**
129
-
130
131
``` java
131
- EtherScanApi api = new EtherScanApi ();
132
- LogQuery query = LogQueryBuilder . with(" 0x33990122638b9132ca29c723bdf037f1a891a70c" , 379224 , 400000 )
133
- .topic(" 0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545" ,
134
- " 0x72657075746174696f6e00000000000000000000000000000000000000000000" ,
135
- " 0x72657075746174696f6e00000000000000000000000000000000000000000000" )
132
+ EtherScanAPI api = EtherScanAPI . build();
133
+ LogQuery query = LogQuery . builder(" 0x33990122638b9132ca29c723bdf037f1a891a70c" )
134
+ .withBlockFrom(379224 )
135
+ .withBlockTo(400000 )
136
+ .withTopic(" 0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545" ,
137
+ " 0x72657075746174696f6e00000000000000000000000000000000000000000000" ,
138
+ " 0x72657075746174696f6e00000000000000000000000000000000000000000000" )
136
139
.setOpTopic0_1(LogOp . AND )
137
- .setOpTopic0_2(LogOp . OR )
140
+ .setOpTopic0_2(null )
138
141
.setOpTopic1_2(LogOp . AND )
139
142
.build();
140
143
141
144
List<Log > logs = api. logs(). logs(query);
142
145
```
143
146
144
- ### Proxy Api
145
-
146
- ** Get tx detailds with proxy endpoint**
147
+ ### Proxy API
147
148
149
+ ** Get tx details with proxy endpoint**
148
150
``` java
149
- EtherScanApi api = new EtherScanApi ( EthNetwork . MAINNET );
151
+ EtherScanAPI api = EtherScanAPI . build( );
150
152
Optional<TxProxy > tx = api. proxy(). tx(" 0x1e2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1" );
151
153
```
152
154
153
155
** Get block info with proxy endpoint**
154
-
155
156
``` java
156
- EtherScanApi api = new EtherScanApi ( EthNetwork . MAINNET );
157
+ EtherScanAPI api = EtherScanAPI . build( );
157
158
Optional<BlockProxy > block = api. proxy(). block(15215 );
158
159
```
159
160
160
- ### Stats Api
161
+ ### Stats API
161
162
162
163
** Statistic about last price**
163
-
164
164
``` java
165
- EtherScanApi api = new EtherScanApi ();
165
+ EtherScanAPI api = EtherScanAPI . build ();
166
166
Price price = api. stats(). lastPrice();
167
167
```
168
168
169
- ### Transaction Api
169
+ ### Transaction API
170
170
171
171
** Request receipt status for tx**
172
-
173
172
``` java
174
- EtherScanApi api = new EtherScanApi ();
173
+ EtherScanAPI api = EtherScanAPI . build ();
175
174
Optional<Boolean > status = api. txs(). receiptStatus(" 0x513c1ba0bebf66436b5fed86ab668452b7805593c05073eb2d51d3a52f480a76" );
176
175
```
177
176
178
- ### Token Api
177
+ ### Token API
179
178
180
- You can read about token API [ here] ( https://etherscan.io/apis# tokens )
179
+ You can read about token API [ here] ( https://docs. etherscan.io/api-endpoints/ tokens )
181
180
182
181
Token API methods migrated to [ Account] ( #account-api ) & [ Stats] ( #stats-api ) respectfully.
183
182
0 commit comments