Git Product home page Git Product logo

java-etherscan-api's Introduction

Java EtherScan API

GitHub Action Coverage Maintainability Rating Lines of Code

Etherscan.io Java API implementation.

Library supports all available EtherScan API calls for all available Ethereum Networks for etherscan.io

Dependency ๐Ÿš€

Gradle

dependencies {
    compile "com.github.goodforgod:java-etherscan-api:1.2.1"
}

Maven

<dependency>
    <groupId>com.github.goodforgod</groupId>
    <artifactId>java-etherscan-api</artifactId>
    <version>1.2.1</version>
</dependency>

Content

Mainnet and Testnets

API support Ethereum: MAINNET, ROPSTEN, KOVAN, RINKEBY, GORLI, TOBALABA networks.

EtherScanApi api = new EtherScanApi(EthNetwork.MAINNET); // Default
EtherScanApi apiRinkeby = new EtherScanApi(EthNetwork.RINKEBY);
EtherScanApi apiRopsten = new EtherScanApi(EthNetwork.ROPSTEN);
EtherScanApi apiKovan = new EtherScanApi("YourApiKey", EthNetwork.KOVAN);

Custom HttpClient

In case you need to set custom timeout, custom headers or better implementation for HttpClient, just implement IHttpExecutor by your self or initialize it with your values.

int connectionTimeout = 10000;
int readTimeout = 7000;
 
Supplier<IHttpExecutor> supplier = () -> new HttpExecutor(connectionTimeout);
Supplier<IHttpExecutor> supplierFull = () -> new HttpExecutor(connectionTimeout, readTimeout);
 
EtherScanApi api = new EtherScanApi(EthNetwork.RINKEBY, supplier);
EtherScanApi apiWithKey = new EtherScanApi("YourApiKey", EthNetwork.MAINNET, supplierFull);

API Examples

You can read about all API methods on Etherscan

Library support all available EtherScan API.

You can use library with or without API key (Check API request\sec restrictions when used without API key).

Library will automatically limit requests up to 5 req/sec when used without key.

EtherScanApi api = new EtherScanApi();
EtherScanApi api = new EtherScanApi("YourApiKey");

Below are examples for each API category.

Account Api

Get Ether Balance for a single Address

EtherScanApi api = new EtherScanApi();
Balance balance = api.account().balance("0x8d4426f94e42f721C7116E81d6688cd935cB3b4F");

Block Api

Get uncles block for block height

EtherScanApi api = new EtherScanApi();
Optional<UncleBlock> uncles = api.block().uncles(200000);

Contract Api

Request contract ABI from verified codes

EtherScanApi api = new EtherScanApi();
Abi abi = api.contract().contractAbi("0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413");

Logs Api

Get event logs for single topic

EtherScanApi api = new EtherScanApi();
LogQuery query = LogQueryBuilder.with("0x33990122638b9132ca29c723bdf037f1a891a70c")
           .topic("0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545")
           .build();
List<Log> logs = api.logs().logs(query);

Get event logs for 3 topics with respectful operations

EtherScanApi api = new EtherScanApi();
LogQuery query = LogQueryBuilder.with("0x33990122638b9132ca29c723bdf037f1a891a70c", 379224, 400000)
        .topic("0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545",
                "0x72657075746174696f6e00000000000000000000000000000000000000000000",
                "0x72657075746174696f6e00000000000000000000000000000000000000000000")
        .setOpTopic0_1(LogOp.AND)
        .setOpTopic0_2(LogOp.OR)
        .setOpTopic1_2(LogOp.AND)
        .build();
 
List<Log> logs = api.logs().logs(query);

Proxy Api

Get tx detailds with proxy endpoint

EtherScanApi api = new EtherScanApi(EthNetwork.MAINNET);
Optional<TxProxy> tx = api.proxy().tx("0x1e2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1");

Get block info with proxy endpoint

EtherScanApi api = new EtherScanApi(EthNetwork.MAINNET);
Optional<BlockProxy> block = api.proxy().block(15215);

Stats Api

Statistic about last price

EtherScanApi api = new EtherScanApi();
Price price = api.stats().lastPrice();

Transaction Api

Request receipt status for tx

EtherScanApi api = new EtherScanApi();
Optional<Boolean> status = api.txs().receiptStatus("0x513c1ba0bebf66436b5fed86ab668452b7805593c05073eb2d51d3a52f480a76");

Token Api

You can read about token API here

Token API methods migrated to Account & Stats respectfully.

License

This project licensed under the MIT - see the LICENSE file for details.

java-etherscan-api's People

Contributors

goodforgod avatar isnow avatar dependabot[bot] avatar guggio avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.