Skip to content

Commit be775cf

Browse files
author
Nathan Guggenberger
committed
Add support for ERC-721 (NFT) Tokens
1 parent 2969dc1 commit be775cf

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/main/java/io/api/etherscan/core/IAccountApi.java

+19-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public interface IAccountApi {
9393
List<TxInternal> txsInternalByHash(String txhash) throws ApiException;
9494

9595
/**
96-
* All token txs for given address
96+
* All ERC-20 token txs for given address
9797
*
9898
* @param address get txs for
9999
* @param startBlock tx from this blockNumber
@@ -110,6 +110,24 @@ public interface IAccountApi {
110110
@NotNull
111111
List<TxToken> txsToken(String address) throws ApiException;
112112

113+
/**
114+
* All ERC-721 (NFT) token txs for given address
115+
*
116+
* @param address get txs for
117+
* @param startBlock tx from this blockNumber
118+
* @param endBlock tx to this blockNumber
119+
* @return txs for address
120+
* @throws ApiException parent exception class
121+
*/
122+
@NotNull
123+
List<TxToken> txsNftToken(String address, long startBlock, long endBlock) throws ApiException;
124+
125+
@NotNull
126+
List<TxToken> txsNftToken(String address, long startBlock) throws ApiException;
127+
128+
@NotNull
129+
List<TxToken> txsNftToken(String address) throws ApiException;
130+
113131
/**
114132
* All blocks mined by address
115133
*

src/main/java/io/api/etherscan/core/impl/AccountApiProvider.java

+24
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class AccountApiProvider extends BasicProvider implements IAccountApi {
3434
private static final String ACT_TX_ACTION = ACT_PREFIX + "txlist";
3535
private static final String ACT_TX_INTERNAL_ACTION = ACT_PREFIX + "txlistinternal";
3636
private static final String ACT_TX_TOKEN_ACTION = ACT_PREFIX + "tokentx";
37+
private static final String ACT_TX_NFT_TOKEN_ACTION = ACT_PREFIX + "tokennfttx";
3738
private static final String ACT_MINED_ACTION = ACT_PREFIX + "getminedblocks";
3839

3940
private static final String BLOCK_TYPE_PARAM = "&blocktype=blocks";
@@ -229,6 +230,29 @@ public List<TxToken> txsToken(final String address, final long startBlock, final
229230
return getRequestUsingOffset(urlParams, TxTokenResponseTO.class);
230231
}
231232

233+
234+
@Override
235+
public @NotNull List<TxToken> txsNftToken(String address) throws ApiException {
236+
return txsNftToken(address, MIN_START_BLOCK);
237+
}
238+
239+
@Override
240+
public @NotNull List<TxToken> txsNftToken(String address, long startBlock) throws ApiException {
241+
return txsNftToken(address, startBlock, MAX_END_BLOCK);
242+
}
243+
244+
@Override
245+
public @NotNull List<TxToken> txsNftToken(String address, long startBlock, long endBlock) throws ApiException {
246+
BasicUtils.validateAddress(address);
247+
final BlockParam blocks = BasicUtils.compensateBlocks(startBlock, endBlock);
248+
249+
final String offsetParam = PAGE_PARAM + "%s" + OFFSET_PARAM + OFFSET_MAX;
250+
final String blockParam = START_BLOCK_PARAM + blocks.start() + END_BLOCK_PARAM + blocks.end();
251+
final String urlParams = ACT_TX_NFT_TOKEN_ACTION + offsetParam + ADDRESS_PARAM + address + blockParam + SORT_ASC_PARAM;
252+
253+
return getRequestUsingOffset(urlParams, TxTokenResponseTO.class);
254+
}
255+
232256
@NotNull
233257
@Override
234258
public List<Block> minedBlocks(final String address) throws ApiException {

0 commit comments

Comments
 (0)