@@ -43,141 +43,140 @@ implementation "com.github.goodforgod:java-etherscan-api:2.0.0-SNAPSHOT"
4343
4444## Mainnet and Testnets
4545
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+ 5251``` 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();
5765```
5866
5967## Custom HttpClient
6068
6169In 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.
6371
6472``` 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();
7377```
7478
7579## API Examples
7680
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 )
7882
7983* Library support all available EtherScan API.*
8084
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 ) )* .
8286
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) .
8488``` java
85- EtherScanApi api = new EtherScanApi ();
86- EtherScanApi api = new EtherScanApi (" YourApiKey" );
89+ EtherScanAPI . builder()
90+ .withApiKey(ApiRunner . API_KEY )
91+ .build();
8792```
8893
8994Below are examples for each API category.
9095
91- ### Account Api
96+ ### Account API
9297
9398** Get Ether Balance for a single Address**
94- 9599``` java
96- EtherScanApi api = new EtherScanApi ();
100+ EtherScanAPI api = EtherScanAPI . build ();
97101Balance balance = api. account(). balance(" 0x8d4426f94e42f721C7116E81d6688cd935cB3b4F" );
98102```
99103
100- ### Block Api
104+ ### Block API
101105
102106** Get uncles block for block height**
103- 104107``` java
105- EtherScanApi api = new EtherScanApi ();
108+ EtherScanAPI api = EtherScanAPI . build ();
106109Optional<UncleBlock > uncles = api. block(). uncles(200000 );
107110```
108111
109- ### Contract Api
112+ ### Contract API
110113** Request contract ABI from [ verified codes] ( https://etherscan.io/contractsVerified ) **
111114``` java
112- EtherScanApi api = new EtherScanApi ();
115+ EtherScanAPI api = EtherScanAPI . build ();
113116Abi abi = api. contract(). contractAbi(" 0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413" );
114117```
115118
116- ### Logs Api
119+ ### Logs API
117120
118121** Get event logs for single topic**
119- 120122``` java
121- EtherScanApi api = new EtherScanApi ();
123+ EtherScanAPI api = EtherScanAPI . build ();
122124LogQuery query = LogQueryBuilder . with(" 0x33990122638b9132ca29c723bdf037f1a891a70c" )
123125 .topic(" 0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545" )
124126 .build();
125127List<Log > logs = api. logs(). logs(query);
126128```
127129
128130** Get event logs for 3 topics with respectful operations**
129- 130131``` 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" )
136139 .setOpTopic0_1(LogOp . AND )
137- .setOpTopic0_2(LogOp . OR )
140+ .setOpTopic0_2(null )
138141 .setOpTopic1_2(LogOp . AND )
139142 .build();
140143
141144List<Log > logs = api. logs(). logs(query);
142145```
143146
144- ### Proxy Api
145- 146- ** Get tx detailds with proxy endpoint**
147+ ### Proxy API
147148
149+ ** Get tx details with proxy endpoint**
148150``` java
149- EtherScanApi api = new EtherScanApi ( EthNetwork . MAINNET );
151+ EtherScanAPI api = EtherScanAPI . build( );
150152Optional<TxProxy > tx = api. proxy(). tx(" 0x1e2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1" );
151153```
152154
153155** Get block info with proxy endpoint**
154- 155156``` java
156- EtherScanApi api = new EtherScanApi ( EthNetwork . MAINNET );
157+ EtherScanAPI api = EtherScanAPI . build( );
157158Optional<BlockProxy > block = api. proxy(). block(15215 );
158159```
159160
160- ### Stats Api
161+ ### Stats API
161162
162163** Statistic about last price**
163- 164164``` java
165- EtherScanApi api = new EtherScanApi ();
165+ EtherScanAPI api = EtherScanAPI . build ();
166166Price price = api. stats(). lastPrice();
167167```
168168
169- ### Transaction Api
169+ ### Transaction API
170170
171171** Request receipt status for tx**
172- 173172``` java
174- EtherScanApi api = new EtherScanApi ();
173+ EtherScanAPI api = EtherScanAPI . build ();
175174Optional<Boolean > status = api. txs(). receiptStatus(" 0x513c1ba0bebf66436b5fed86ab668452b7805593c05073eb2d51d3a52f480a76" );
176175```
177176
178- ### Token Api
177+ ### Token API
179178
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 )
181180
182181Token API methods migrated to [ Account] ( #account-api ) & [ Stats] ( #stats-api ) respectfully.
183182
0 commit comments