1
- const querystring = require ( ' querystring' ) ;
2
- module . exports = function ( getRequest , apiKey ) {
1
+ const querystring = require ( " querystring" ) ;
2
+ module . exports = function ( getRequest , apiKey ) {
3
3
return {
4
4
/**
5
5
* Returns the amount of Tokens a specific account owns.
@@ -15,13 +15,15 @@ module.exports = function(getRequest, apiKey) {
15
15
* @returns {Promise.<object> }
16
16
*/
17
17
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" ;
22
21
23
22
var queryObject = {
24
- module, action, apiKey, tag
23
+ module,
24
+ action,
25
+ apiKey,
26
+ tag,
25
27
} ;
26
28
27
29
if ( contractaddress ) {
@@ -47,17 +49,21 @@ module.exports = function(getRequest, apiKey) {
47
49
* @returns {Promise.<object> }
48
50
*/
49
51
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" ;
53
55
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" ;
57
59
}
58
60
59
61
var query = querystring . stringify ( {
60
- module, action, tag, address, apiKey
62
+ module,
63
+ action,
64
+ tag,
65
+ address,
66
+ apiKey,
61
67
} ) ;
62
68
return getRequest ( query ) ;
63
69
} ,
@@ -73,13 +79,13 @@ module.exports = function(getRequest, apiKey) {
73
79
* @returns {Promise.<object> }
74
80
*/
75
81
txlistinternal ( txhash , address , startblock , endblock , sort ) {
76
- const module = ' account' ;
77
- const action = ' txlistinternal' ;
82
+ const module = " account" ;
83
+ const action = " txlistinternal" ;
78
84
79
85
var queryObject = {
80
86
module,
81
87
action,
82
- apiKey
88
+ apiKey,
83
89
} ;
84
90
85
91
if ( ! startblock ) {
@@ -88,12 +94,12 @@ module.exports = function(getRequest, apiKey) {
88
94
queryObject . startblock = startblock ;
89
95
90
96
if ( ! endblock ) {
91
- endblock = ' latest' ;
97
+ endblock = " latest" ;
92
98
}
93
99
queryObject . endblock = endblock ;
94
100
95
101
if ( ! sort ) {
96
- sort = ' asc' ;
102
+ sort = " asc" ;
97
103
}
98
104
queryObject . sort = sort ;
99
105
@@ -120,15 +126,15 @@ module.exports = function(getRequest, apiKey) {
120
126
* @returns {Promise.<object> }
121
127
*/
122
128
txlist ( address , startblock , endblock , page , offset , sort ) {
123
- const module = ' account' ;
124
- const action = ' txlist' ;
129
+ const module = " account" ;
130
+ const action = " txlist" ;
125
131
126
132
if ( ! startblock ) {
127
133
startblock = 0 ;
128
134
}
129
135
130
136
if ( ! endblock ) {
131
- endblock = ' latest' ;
137
+ endblock = " latest" ;
132
138
}
133
139
134
140
if ( ! page ) {
@@ -140,11 +146,19 @@ module.exports = function(getRequest, apiKey) {
140
146
}
141
147
142
148
if ( ! sort ) {
143
- sort = ' asc' ;
149
+ sort = " asc" ;
144
150
}
145
151
146
152
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,
148
162
} ) ;
149
163
150
164
return getRequest ( query ) ;
@@ -156,59 +170,141 @@ module.exports = function(getRequest, apiKey) {
156
170
* @param {string } address - Transaction hash
157
171
*/
158
172
getminedblocks ( address ) {
159
- const module = ' account' ;
160
- const action = ' getminedblocks' ;
173
+ const module = " account" ;
174
+ const action = " getminedblocks" ;
161
175
var query = querystring . stringify ( {
162
- module, action, address, apiKey
176
+ module,
177
+ action,
178
+ address,
179
+ apiKey,
163
180
} ) ;
164
181
return getRequest ( query ) ;
165
182
} ,
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
168
185
* @param {string } address - Account address
169
186
* @param {string } startblock - start looking here
170
187
* @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
174
191
* @param {string } contractaddress - Address of ERC20 token contract (if not specified lists transfers for all tokens)
175
192
* @example
176
193
* var txlist = api.account.tokentx('0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae', '0x5F988D968cb76c34C87e6924Cc1Ef1dCd4dE75da', 1, 'latest', 'asc');
177
194
* @returns {Promise.<object> }
178
195
*/
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" ;
182
270
183
271
if ( ! startblock ) {
184
272
startblock = 0 ;
185
273
}
186
274
187
275
if ( ! endblock ) {
188
- endblock = ' latest' ;
276
+ endblock = " latest" ;
189
277
}
190
278
191
- if ( ! page ) {
192
- page = 1 ;
193
- }
279
+ if ( ! page ) {
280
+ page = 1 ;
281
+ }
194
282
195
- if ( ! offset ) {
196
- offset = 100 ;
197
- }
283
+ if ( ! offset ) {
284
+ offset = 0 ;
285
+ }
198
286
199
287
if ( ! sort ) {
200
- sort = ' asc' ;
288
+ sort = " asc" ;
201
289
}
202
290
203
291
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,
205
301
} ;
206
302
207
303
if ( contractaddress ) {
208
304
queryObject . contractaddress = contractaddress ;
209
305
}
210
306
211
307
return getRequest ( querystring . stringify ( queryObject ) ) ;
212
- }
308
+ } ,
213
309
} ;
214
310
} ;
0 commit comments