- Notifications
You must be signed in to change notification settings - Fork42
🔗 Polished Java library for EtherScan.io API
License
GoodforGod/java-etherscan-api
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Etherscan.io Java API implementation.
Library supports EtherScanAPI for all availableEthereum Networks foretherscan.io
Gradle
implementation"com.github.goodforgod:java-etherscan-api:2.1.0"
Maven
<dependency> <groupId>com.github.goodforgod</groupId> <artifactId>java-etherscan-api</artifactId> <version>2.1.0</version></dependency>
API support all Ethereumdefault networks:
EtherScanAPIapi =EtherScanAPI.builder().build();EtherScanAPIapiGoerli =EtherScanAPI.builder().withNetwork(EthNetworks.GORLI).build();EtherScanAPIapiSepolia =EtherScanAPI.builder().withNetwork(EthNetworks.SEPOLIA).build();
In case you want to use API for other EtherScan compatible network, you can easily provide custom network with domain api URI.
EtherScanAPIapi =EtherScanAPI.builder() .withNetwork(() ->URI.create("https://api-my-custom.etherscan.io/api")) .build();
In case you need to set custom timeout, custom headers or better implementation for HttpClient,just implementEthHttpClient by your self or initialize it with your values.
Supplier<EthHttpClient>ethHttpClientSupplier = () ->newUrlEthHttpClient(Duration.ofMillis(300),Duration.ofMillis(300));EtherScanAPIapi =EtherScanAPI.builder() .withHttpClient(supplier) .build();
You can read about all API methods onEtherscan
Library support all available EtherScan API.
You can use librarywith or without API key(Check API request\sec restrictions when used without API key).
Library will automatically limit requests up to1 requests in 5 seconds when usedwithout key and up to5 requests in 1 seconds when used with API KEY (free plan).
EtherScanAPI.builder() .withApiKey(ApiRunner.API_KEY) .build();
Below are examples for each API category.
Get Ether Balance for a single Address
EtherScanAPIapi =EtherScanAPI.builder().build();Balancebalance =api.account().balance("0x8d4426f94e42f721C7116E81d6688cd935cB3b4F");
Get uncles block for block height
EtherScanAPIapi =EtherScanAPI.builder().build();Optional<UncleBlock>uncles =api.block().uncles(200000);
Request contract ABI fromverified codes
EtherScanAPIapi =EtherScanAPI.builder().build();Abiabi =api.contract().contractAbi("0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413");
Get event logs for single topic
EtherScanAPIapi =EtherScanAPI.builder().build();LogQueryquery =LogQuery.builder("0x33990122638b9132ca29c723bdf037f1a891a70c") .withTopic("0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545") .build();List<Log>logs =api.logs().logs(query);
Get event logs for 3 topics with respectful operations
EtherScanAPIapi =EtherScanAPI.builder().build();LogQueryquery =LogQuery.builder("0x33990122638b9132ca29c723bdf037f1a891a70c") .withBlockFrom(379224) .withBlockTo(400000) .withTopic("0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545","0x72657075746174696f6e00000000000000000000000000000000000000000000","0x72657075746174696f6e00000000000000000000000000000000000000000000") .setOpTopic0_1(LogOp.AND) .setOpTopic0_2(null) .setOpTopic1_2(LogOp.AND) .build();List<Log>logs =api.logs().logs(query);
Get tx details with proxy endpoint
EtherScanAPIapi =EtherScanAPI.builder().build();Optional<TxProxy>tx =api.proxy().tx("0x1e2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1");
Get block info with proxy endpoint
EtherScanAPIapi =EtherScanAPI.builder().build();Optional<BlockProxy>block =api.proxy().block(15215);
Statistic about last price
EtherScanAPIapi =EtherScanAPI.builder().build();Priceprice =api.stats().priceLast();
Request receipt status for tx
EtherScanAPIapi =EtherScanAPI.builder().build();Optional<Boolean>status =api.txs().receiptStatus("0x513c1ba0bebf66436b5fed86ab668452b7805593c05073eb2d51d3a52f480a76");
You can read about token APIhere
Token API methods migrated toAccount &Stats respectfully.
This project licensed under the MIT - see theLICENSE file for details.
About
🔗 Polished Java library for EtherScan.io API
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Contributors6
Uh oh!
There was an error while loading.Please reload this page.