Skip to content

Commit 4025a33

Browse files
committed
Add tokennfttx account endpoint
1 parent f1cbf5d commit 4025a33

File tree

3 files changed

+3579
-6526
lines changed

3 files changed

+3579
-6526
lines changed

lib/account.js

Lines changed: 141 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const querystring = require('querystring');
2-
module.exports = function(getRequest, apiKey) {
1+
const querystring = require("querystring");
2+
module.exports = function (getRequest, apiKey) {
33
return {
44
/**
55
* Returns the amount of Tokens a specific account owns.
@@ -15,13 +15,15 @@ module.exports = function(getRequest, apiKey) {
1515
* @returns {Promise.<object>}
1616
*/
1717
tokenbalance(address, tokenname, contractaddress) {
18-
19-
const module = 'account';
20-
const action = 'tokenbalance';
21-
const tag = 'latest';
18+
const module = "account";
19+
const action = "tokenbalance";
20+
const tag = "latest";
2221

2322
var queryObject = {
24-
module, action, apiKey, tag
23+
module,
24+
action,
25+
apiKey,
26+
tag,
2527
};
2628

2729
if (contractaddress) {
@@ -47,17 +49,21 @@ module.exports = function(getRequest, apiKey) {
4749
* @returns {Promise.<object>}
4850
*/
4951
balance(address) {
50-
const module = 'account';
51-
let action = 'balance';
52-
const tag = 'latest';
52+
const module = "account";
53+
let action = "balance";
54+
const tag = "latest";
5355

54-
if (typeof address !== 'string' && address && address.length) {
55-
address = address.join(',');
56-
action = 'balancemulti';
56+
if (typeof address !== "string" && address && address.length) {
57+
address = address.join(",");
58+
action = "balancemulti";
5759
}
5860

5961
var query = querystring.stringify({
60-
module, action, tag, address, apiKey
62+
module,
63+
action,
64+
tag,
65+
address,
66+
apiKey,
6167
});
6268
return getRequest(query);
6369
},
@@ -73,13 +79,13 @@ module.exports = function(getRequest, apiKey) {
7379
* @returns {Promise.<object>}
7480
*/
7581
txlistinternal(txhash, address, startblock, endblock, sort) {
76-
const module = 'account';
77-
const action = 'txlistinternal';
82+
const module = "account";
83+
const action = "txlistinternal";
7884

7985
var queryObject = {
8086
module,
8187
action,
82-
apiKey
88+
apiKey,
8389
};
8490

8591
if (!startblock) {
@@ -88,12 +94,12 @@ module.exports = function(getRequest, apiKey) {
8894
queryObject.startblock = startblock;
8995

9096
if (!endblock) {
91-
endblock = 'latest';
97+
endblock = "latest";
9298
}
9399
queryObject.endblock = endblock;
94100

95101
if (!sort) {
96-
sort = 'asc';
102+
sort = "asc";
97103
}
98104
queryObject.sort = sort;
99105

@@ -120,15 +126,15 @@ module.exports = function(getRequest, apiKey) {
120126
* @returns {Promise.<object>}
121127
*/
122128
txlist(address, startblock, endblock, page, offset, sort) {
123-
const module = 'account';
124-
const action = 'txlist';
129+
const module = "account";
130+
const action = "txlist";
125131

126132
if (!startblock) {
127133
startblock = 0;
128134
}
129135

130136
if (!endblock) {
131-
endblock = 'latest';
137+
endblock = "latest";
132138
}
133139

134140
if (!page) {
@@ -140,11 +146,19 @@ module.exports = function(getRequest, apiKey) {
140146
}
141147

142148
if (!sort) {
143-
sort = 'asc';
149+
sort = "asc";
144150
}
145151

146152
var query = querystring.stringify({
147-
module, action, startblock, endblock, page, offset, sort, address, apiKey
153+
module,
154+
action,
155+
startblock,
156+
endblock,
157+
page,
158+
offset,
159+
sort,
160+
address,
161+
apiKey,
148162
});
149163

150164
return getRequest(query);
@@ -156,59 +170,141 @@ module.exports = function(getRequest, apiKey) {
156170
* @param {string} address - Transaction hash
157171
*/
158172
getminedblocks(address) {
159-
const module = 'account';
160-
const action = 'getminedblocks';
173+
const module = "account";
174+
const action = "getminedblocks";
161175
var query = querystring.stringify({
162-
module, action, address, apiKey
176+
module,
177+
action,
178+
address,
179+
apiKey,
163180
});
164181
return getRequest(query);
165182
},
166-
/**
167-
* [BETA] Get a list of "ERC20 - Token Transfer Events" by Address
183+
/**
184+
* Get a list of "ERC20 - Token Transfer Events" by Address
168185
* @param {string} address - Account address
169186
* @param {string} startblock - start looking here
170187
* @param {string} endblock - end looking there
171-
* @param {number} page - Page number
172-
* @param {number} offset - Max records to return
173-
* @param {string} sort - Sort asc/desc
188+
* @param {number} page - Page number
189+
* @param {number} offset - Max records to return
190+
* @param {string} sort - Sort asc/desc
174191
* @param {string} contractaddress - Address of ERC20 token contract (if not specified lists transfers for all tokens)
175192
* @example
176193
* var txlist = api.account.tokentx('0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae', '0x5F988D968cb76c34C87e6924Cc1Ef1dCd4dE75da', 1, 'latest', 'asc');
177194
* @returns {Promise.<object>}
178195
*/
179-
tokentx(address, contractaddress, startblock, endblock, page, offset, sort) {
180-
const module = 'account';
181-
const action = 'tokentx';
196+
tokentx(
197+
address,
198+
contractaddress,
199+
startblock,
200+
endblock,
201+
page,
202+
offset,
203+
sort
204+
) {
205+
const module = "account";
206+
const action = "tokentx";
207+
208+
if (!startblock) {
209+
startblock = 0;
210+
}
211+
212+
if (!endblock) {
213+
endblock = "latest";
214+
}
215+
216+
if (!page) {
217+
page = 1;
218+
}
219+
220+
if (!offset) {
221+
offset = 0;
222+
}
223+
224+
if (!sort) {
225+
sort = "asc";
226+
}
227+
228+
var queryObject = {
229+
module,
230+
action,
231+
startblock,
232+
endblock,
233+
page,
234+
offset,
235+
sort,
236+
address,
237+
apiKey,
238+
};
239+
240+
if (contractaddress) {
241+
queryObject.contractaddress = contractaddress;
242+
}
243+
244+
return getRequest(querystring.stringify(queryObject));
245+
},
246+
/**
247+
* Get a list of "ERC721 - Token Transfer Events" by Address
248+
* @param {string} address - Account address
249+
* @param {string} startblock - start looking here
250+
* @param {string} endblock - end looking there
251+
* @param {number} page - Page number
252+
* @param {number} offset - Max records to return
253+
* @param {string} sort - Sort asc/desc
254+
* @param {string} contractaddress - Address of ERC721 token contract (if not specified lists transfers for all tokens)
255+
* @example
256+
* var txnftlist = api.account.tokennfttx('0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae', '0x5F988D968cb76c34C87e6924Cc1Ef1dCd4dE75da', 1, 'latest', 'asc');
257+
* @returns {Promise.<object>}
258+
*/
259+
tokennfttx(
260+
address,
261+
contractaddress,
262+
startblock,
263+
endblock,
264+
page,
265+
offset,
266+
sort
267+
) {
268+
const module = "account";
269+
const action = "tokennfttx";
182270

183271
if (!startblock) {
184272
startblock = 0;
185273
}
186274

187275
if (!endblock) {
188-
endblock = 'latest';
276+
endblock = "latest";
189277
}
190278

191-
if (!page) {
192-
page = 1;
193-
}
279+
if (!page) {
280+
page = 1;
281+
}
194282

195-
if (!offset) {
196-
offset = 100;
197-
}
283+
if (!offset) {
284+
offset = 0;
285+
}
198286

199287
if (!sort) {
200-
sort = 'asc';
288+
sort = "asc";
201289
}
202290

203291
var queryObject = {
204-
module, action, startblock, endblock, page, offset, sort, address, apiKey
292+
module,
293+
action,
294+
startblock,
295+
endblock,
296+
page,
297+
offset,
298+
sort,
299+
address,
300+
apiKey,
205301
};
206302

207303
if (contractaddress) {
208304
queryObject.contractaddress = contractaddress;
209305
}
210306

211307
return getRequest(querystring.stringify(queryObject));
212-
}
308+
},
213309
};
214310
};

0 commit comments

Comments
 (0)