Skip to content

Release 1.0.1 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 9, 2019
35 changes: 22 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ Library supports all available EtherScan *API* calls for all available *Ethereum
<dependency>
<groupId>com.github.goodforgod</groupId>
<artifactId>java-etherscan-api</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
</dependency>
```

**Gradle**
```groovy
dependencies {
compile 'com.github.goodforgod:java-etherscan-api:1.0.0'
compile 'com.github.goodforgod:java-etherscan-api:1.0.1'
}
```

Expand All @@ -40,12 +40,17 @@ dependencies {
- [Version History](#version-history)

## Mainnet and Testnets
API support Ethereum: *[MAINNET](https://etherscan.io), [ROPSTEN](https://ropsten.etherscan.io),
[KOVAN](https://kovan.etherscan.io), [RINKEBY](https://rinkeby.etherscan.io)* networks.
API support Ethereum: *[MAINNET](https://etherscan.io),
[ROPSTEN](https://ropsten.etherscan.io),
[KOVAN](https://kovan.etherscan.io),
[RINKEBY](https://rinkeby.etherscan.io),
[GORLI](https://goerli.etherscan.io),
[TOBALABA](https://tobalaba.etherscan.com)* networks.
```java
EtherScanApi api = new EtherScanApi(EthNetwork.MAINTNET);
EtherScanApi api = new EtherScanApi(EthNetwork.RINKEBY);
EtherScanApi api = new EtherScanApi("YourApiKey", EthNetwork.KOVAN);
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
Expand All @@ -56,10 +61,10 @@ just implement **IHttpExecutor** by your self or initialize it with your values.
```java
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);
```
Expand All @@ -70,14 +75,15 @@ You can read about all API methods on [Etherscan](https://etherscan.io/apis)

*Library support all available EtherScan API.*

You can use API with you key or without key as well (Check API request\sec restrictions).
Library support limit when used without key and will limit requests up to *5 req/sec by itself*.
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))*.

Library will automatically limit requests up to **5 req/sec** when used *without* key.
```java
EtherScanApi api = new EtherScanApi();
EtherScanApi api = new EtherScanApi("YourApiKey");
```

Below there are examples for each API category.
Below are examples for each API category.

### Account Api
**Get Ether Balance for a single Address**
Expand Down Expand Up @@ -121,6 +127,7 @@ LogQuery query = LogQueryBuilder.with("0x33990122638b9132ca29c723bdf037f1a891a70
.setOpTopic0_2(LogOp.OR)
.setOpTopic1_2(LogOp.AND)
.build();

List<Log> logs = api.logs().logs(query);
```

Expand Down Expand Up @@ -152,12 +159,14 @@ Optional<Boolean> status = api.txs().receiptStatus("0x513c1ba0bebf66436b5fed86ab
```

### Token Api
You can read token API [here](https://etherscan.io/apis#tokens)
You can read about token API [here](https://etherscan.io/apis#tokens)

Token API methods migrated to [Account](#account-api) & [Stats](#stats-api) respectfully.

## Version History

**1.0.1** - Gorli & TOBALABA networks support.

**1.0.0** - Initial project with all API functionality, for all available networks, with tests coverage for all cases.

## License
Expand Down
7 changes: 5 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.github.goodforgod</groupId>
<artifactId>java-etherscan-api</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
<packaging>jar</packaging>

<name>${project.groupId}:${project.artifactId}</name>
Expand Down Expand Up @@ -53,7 +53,7 @@
<maven-build-plugin-version>3.0.2</maven-build-plugin-version>
<maven-gpg-plugin-version>1.6</maven-gpg-plugin-version>
<maven-source-plugin-version>3.0.1</maven-source-plugin-version>
<maven-javadoc-plugin-version>2.10.4</maven-javadoc-plugin-version>
<maven-javadoc-plugin-version>3.0.1</maven-javadoc-plugin-version>
<maven-nexus-staging-maven-plugin-version>1.6.8</maven-nexus-staging-maven-plugin-version>
<cobertura-plugin-version>2.7</cobertura-plugin-version>

Expand Down Expand Up @@ -157,6 +157,9 @@
</goals>
</execution>
</executions>
<configuration>
<additionalOptions>-html5</additionalOptions>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/io/api/etherscan/App.java

This file was deleted.

41 changes: 34 additions & 7 deletions src/main/java/io/api/etherscan/core/IAccountApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,61 @@
*/
public interface IAccountApi {

/** Address ETH balance */
/**
* Address ETH balance
* @param address to look for
* @return balance
*/
@NotNull Balance balance(String address) throws ApiException;

/** ERC20 token balance for address */
/**
* ERC20 token balance for address
* @param address to look for
* @param contract for token
* @return token balance
*/
@NotNull TokenBalance balance(String address, String contract) throws ApiException;

/**
* Maximum 20 address for single batch request
* If address > 20, then there will be more than 1 request performed
* If addresses more than 20, then there will be MORE than 1 request performed
* @param addresses to look for
* @return balance[0] for address[0], etc
*/
@NotNull List<Balance> balances(List<String> addresses) throws ApiException;

/** All txs */
/**
* Find all txs
* @param address to look for txs
* @return tx info
*/
@NotNull List<Tx> txs(String address) throws ApiException;
@NotNull List<Tx> txs(String address, long startBlock) throws ApiException;
@NotNull List<Tx> txs(String address, long startBlock, long endBlock) throws ApiException;

/** All internal txs */
/**
* All internal txs
* @param address to look for
* @return internal tx
*/
@NotNull List<TxInternal> txsInternal(String address) throws ApiException;
@NotNull List<TxInternal> txsInternal(String address, long startBlock) throws ApiException;
@NotNull List<TxInternal> txsInternal(String address, long startBlock, long endBlock) throws ApiException;
@NotNull List<TxInternal> txsInternalByHash(String txhash);

/** All token txs */
/**
* All token txs
* @param address to look for
* @return token txs
*/
@NotNull List<TxToken> txsToken(String address) throws ApiException;
@NotNull List<TxToken> txsToken(String address, long startBlock) throws ApiException;
@NotNull List<TxToken> txsToken(String address, long startBlock, long endBlock) throws ApiException;

/** All blocks mined by address */
/**
* All blocks mined by address
* @param address to look for
* @return mined blocks
*/
@NotNull List<Block> minedBlocks(String address) throws ApiException;
}
6 changes: 5 additions & 1 deletion src/main/java/io/api/etherscan/core/IBlockApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
*/
public interface IBlockApi {

/** Return uncle blocks */
/**
* Return uncle blocks
* @param blockNumber block number
* @return uncle block
*/
@NotNull Optional<UncleBlock> uncles(long blockNumber) throws ApiException;
}
6 changes: 5 additions & 1 deletion src/main/java/io/api/etherscan/core/IContractApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
*/
public interface IContractApi {

/** Get Verified Contract Sources */
/**
* Get Verified Contract Sources
* @param address to look for
* @return abi for contract
*/
@NotNull Abi contractAbi(String address) throws ApiException;
}
5 changes: 4 additions & 1 deletion src/main/java/io/api/etherscan/core/ILogsApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
public interface ILogsApi {

/**
* alternative to the native eth_getLogs
* Alternative to the native eth_getLogs
* Read at EtherScan API description for full info!
* @see LogQuery
* @param query for logs (check etherscan specs)
* @return logs
*/
@NotNull List<Log> logs(LogQuery query) throws ApiException;
}
29 changes: 29 additions & 0 deletions src/main/java/io/api/etherscan/core/IProxyApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,86 +21,115 @@ public interface IProxyApi {
/**
* Returns the number of most recent block
* eth_blockNumber
* @return last block number
*/
long blockNoLast();

/**
* Returns information about a block by block number
* eth_getBlockByNumber
* @param blockNo block number
* @return block info
*/
@NotNull Optional<BlockProxy> block(long blockNo) throws ApiException;

/**
* Returns information about a uncle by block number
* eth_getUncleByBlockNumberAndIndex
* @param blockNo block number
* @param index uncle block index
* @return block info
*/
@NotNull Optional<BlockProxy> blockUncle(long blockNo, long index) throws ApiException;

/**
* Returns the information about a transaction requested by transaction hash
* eth_getTransactionByHash
* @param txhash tx hash
* @return tx info
*/
@NotNull Optional<TxProxy> tx(String txhash) throws ApiException;

/**
* Returns information about a transaction by block number and transaction index position
* eth_getTransactionByBlockNumberAndIndex
* @param blockNo block number
* @param index tx index in block
* @return tx info
*/
@NotNull Optional<TxProxy> tx(long blockNo, long index) throws ApiException;

/**
* Returns the number of transactions in a block from a block matching the given block number
* eth_getBlockTransactionCountByNumber
* @param blockNo block number
* @return tx count in block
*/
int txCount(long blockNo) throws ApiException;

/**
* Returns the number of transactions sent from an address
* eth_getTransactionCount
* @param address to look for
* @return tx send count
*/
int txSendCount(String address) throws ApiException;

/**
* Creates new message call transaction or a contract creation for signed transactions
* eth_sendRawTransaction
* @param hexEncodedTx tx as hex
* @return result (check eth grpc info)
*/
@NotNull Optional<String> txSendRaw(String hexEncodedTx) throws ApiException;

/**
* Returns the receipt of a transaction by transaction hash
* eth_getTransactionReceipt
* @param txhash tx hash
* @return receipt
*/
@NotNull Optional<ReceiptProxy> txReceipt(String txhash) throws ApiException;

/**
* Executes a new message call immediately without creating a transaction on the block chain
* eth_call
* @param address to look for
* @param data in tx for call
* @return result (check eth grpc info)
*/
@NotNull Optional<String> call(String address, String data) throws ApiException;

/**
* Returns code at a given address
* eth_getCode
* @param address to look for
* @return result (check eth grpc info)
*/
@NotNull Optional<String> code(String address) throws ApiException;

/**
* (**experimental)
* Returns the value from a storage position at a given address
* eth_getStorageAt
* @param address to look for
* @param position storage position
* @return result (check eth grpc info)
*/
@NotNull Optional<String> storageAt(String address, long position) throws ApiException;

/**
* Returns the current price per gas in wei
* eth_gasPrice
* @return price
*/
@NotNull BigInteger gasPrice() throws ApiException;

/**
* Makes a call or transaction, which won't be added to the blockchain and returns the used gas,
* which can be used for estimating the used gas
* eth_estimateGas
* @return gas estimate
*/
@NotNull BigInteger gasEstimated() throws ApiException;
@NotNull BigInteger gasEstimated(String hexData) throws ApiException;
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/io/api/etherscan/core/IStatisticApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,22 @@
*/
public interface IStatisticApi {

/** ERC20 token total Supply */
/**
* ERC20 token total Supply
* @param contract to look for
* @return token supply
*/
@NotNull BigInteger supply(String contract) throws ApiException;

/** Eth total supply */
/**
* Eth total supply
* @return ETH supply
*/
@NotNull Supply supply() throws ApiException;

/** Eth last USD and BTC price */
/**
* Eth last USD and BTC price
* @return last price
*/
@NotNull Price lastPrice() throws ApiException;
}
Loading