@@ -1188,26 +1188,21 @@ public static async Task<NFT> ERC721_GetNFT(this ThirdwebContract contract, BigI
1188
1188
/// </summary>
1189
1189
/// <param name="contract">The contract to interact with.</param>
1190
1190
/// <param name="startTokenId">The starting token ID (inclusive). Defaults to 0 if not specified.</param>
1191
- /// <param name="count">The number of tokens to retrieve. Defaults to the total supply if not specified.</param>
1191
+ /// <param name="count">The number of tokens to retrieve. Defaults to 100 if not specified.</param>
1192
1192
/// <returns>A task representing the asynchronous operation, with a list of NFT results containing the token details.</returns>
1193
1193
/// <exception cref="ArgumentNullException">Thrown when the contract is null.</exception>
1194
- public static async Task < List < NFT > > ERC721_GetAllNFTs ( this ThirdwebContract contract , BigInteger ? startTokenId = null , BigInteger ? count = null )
1194
+ public static async Task < List < NFT > > ERC721_GetAllNFTs ( this ThirdwebContract contract , int startTokenId = 0 , int count = 100 )
1195
1195
{
1196
1196
if ( contract == null )
1197
1197
{
1198
1198
throw new ArgumentNullException ( nameof ( contract ) ) ;
1199
1199
}
1200
1200
1201
- if ( startTokenId == null )
1202
- {
1203
- startTokenId = 0 ;
1204
- }
1205
-
1206
1201
var totalSupply = await contract . ERC721_TotalSupply ( ) . ConfigureAwait ( false ) ;
1207
- count = count == null ? totalSupply - startTokenId : Math . Min ( ( int ) count , ( int ) ( totalSupply - startTokenId ) ) ;
1202
+ count = Math . Min ( count , ( int ) ( totalSupply - startTokenId ) ) ;
1208
1203
1209
1204
var nftTasks = new List < Task < NFT > > ( ) ;
1210
- for ( var i = startTokenId . Value ; i < startTokenId . Value + count . Value ; i ++ )
1205
+ for ( var i = startTokenId ; i < startTokenId + count ; i ++ )
1211
1206
{
1212
1207
nftTasks . Add ( contract . ERC721_GetNFT ( i ) ) ;
1213
1208
}
@@ -1221,13 +1216,13 @@ public static async Task<List<NFT>> ERC721_GetAllNFTs(this ThirdwebContract cont
1221
1216
/// </summary>
1222
1217
/// <param name="contract">The contract to interact with.</param>
1223
1218
/// <param name="owner">The address of the owner.</param>
1224
- /// <param name="startTokenId">The starting token ID (inclusive). Defaults to null if not specified.</param>
1225
- /// <param name="count">The number of tokens to retrieve. Defaults to null if not specified.</param>
1219
+ /// <param name="startTokenId">The starting token ID (inclusive). Defaults to 0 if not specified.</param>
1220
+ /// <param name="count">The number of tokens to retrieve. Defaults to 100 if not specified.</param>
1226
1221
/// <returns>A task representing the asynchronous operation, with a list of NFT results containing the token details.</returns>
1227
1222
/// <remarks>ERC721AQueryable and ERC721Enumerable are supported.</remarks>
1228
1223
/// <exception cref="ArgumentNullException">Thrown when the contract is null.</exception>
1229
1224
/// <exception cref="ArgumentException">Thrown when the owner address is null or empty.</exception>
1230
- public static async Task < List < NFT > > ERC721_GetOwnedNFTs ( this ThirdwebContract contract , string owner , BigInteger ? startTokenId = null , BigInteger ? count = null )
1225
+ public static async Task < List < NFT > > ERC721_GetOwnedNFTs ( this ThirdwebContract contract , string owner , int startTokenId = 0 , int count = 100 )
1231
1226
{
1232
1227
if ( contract == null )
1233
1228
{
@@ -1239,105 +1234,51 @@ public static async Task<List<NFT>> ERC721_GetOwnedNFTs(this ThirdwebContract co
1239
1234
throw new ArgumentException ( "Owner must be provided" ) ;
1240
1235
}
1241
1236
1242
- if ( startTokenId == null )
1243
- {
1244
- startTokenId = 0 ;
1245
- }
1237
+ var totalSupply = await contract . ERC721_TotalSupply ( ) . ConfigureAwait ( false ) ;
1238
+ count = Math . Min ( count , ( int ) ( totalSupply - startTokenId ) ) ;
1246
1239
1247
- // Paginated
1248
- if ( count != null )
1240
+ // ERC721AQueryable
1241
+ try
1249
1242
{
1250
- var totalSupply = await contract . ERC721_TotalSupply ( ) . ConfigureAwait ( false ) ;
1251
- count = Math . Min ( ( int ) count , ( int ) ( totalSupply - startTokenId ) ) ;
1252
-
1253
- // ERC721AQueryable
1254
- try
1243
+ var tokensOfOwnerIn = await contract . ERC721A_TokensOfOwnerIn ( owner , startTokenId , startTokenId + count ) . ConfigureAwait ( false ) ;
1244
+ var ownedNftTasks = new List < Task < NFT > > ( ) ;
1245
+ foreach ( var tokenId in tokensOfOwnerIn )
1255
1246
{
1256
- var tokensOfOwnerIn = await contract . ERC721A_TokensOfOwnerIn ( owner , startTokenId . Value , startTokenId . Value + count . Value ) . ConfigureAwait ( false ) ;
1257
- var ownedNftTasks = new List < Task < NFT > > ( ) ;
1258
- foreach ( var tokenId in tokensOfOwnerIn )
1259
- {
1260
- ownedNftTasks . Add ( contract . ERC721_GetNFT ( tokenId ) ) ;
1261
- }
1262
- var ownedNfts = await Task . WhenAll ( ownedNftTasks ) . ConfigureAwait ( false ) ;
1263
- return ownedNfts . ToList ( ) ;
1264
- }
1265
- catch
1266
- {
1267
- // ERC721Enumerable
1268
- try
1269
- {
1270
- var balanceOfOwner = await contract . ERC721_BalanceOf ( owner ) . ConfigureAwait ( false ) ;
1271
- var ownedNftTasks = new List < Task < NFT > > ( ) ;
1272
- for ( var i = 0 ; i < balanceOfOwner ; i ++ )
1273
- {
1274
- var tokenOfOwnerByIndex = await contract . ERC721_TokenOfOwnerByIndex ( owner , i ) . ConfigureAwait ( false ) ;
1275
- if ( tokenOfOwnerByIndex >= startTokenId && tokenOfOwnerByIndex < startTokenId + count )
1276
- {
1277
- ownedNftTasks . Add ( contract . ERC721_GetNFT ( tokenOfOwnerByIndex ) ) ;
1278
- }
1279
- }
1280
- var ownedNfts = await Task . WhenAll ( ownedNftTasks ) . ConfigureAwait ( false ) ;
1281
- return ownedNfts . ToList ( ) ;
1282
- }
1283
- catch ( Exception )
1284
- {
1285
- var allNfts = await contract . ERC721_GetAllNFTs ( startTokenId , count ) . ConfigureAwait ( false ) ;
1286
- var ownedNfts = new List < NFT > ( ) ;
1287
- foreach ( var nft in allNfts )
1288
- {
1289
- if ( nft . Owner == owner )
1290
- {
1291
- ownedNfts . Add ( nft ) ;
1292
- }
1293
- }
1294
- return ownedNfts . ToList ( ) ;
1295
- }
1247
+ ownedNftTasks . Add ( contract . ERC721_GetNFT ( tokenId ) ) ;
1296
1248
}
1249
+ var ownedNfts = await Task . WhenAll ( ownedNftTasks ) . ConfigureAwait ( false ) ;
1250
+ return ownedNfts . ToList ( ) ;
1297
1251
}
1298
- // All
1299
- else
1252
+ catch
1300
1253
{
1254
+ // ERC721Enumerable
1301
1255
try
1302
1256
{
1303
- // ERC721AQueryable
1304
- var tokensOfOwner = await contract . ERC721A_TokensOfOwner ( owner ) . ConfigureAwait ( false ) ;
1257
+ var balanceOfOwner = await contract . ERC721_BalanceOf ( owner ) . ConfigureAwait ( false ) ;
1305
1258
var ownedNftTasks = new List < Task < NFT > > ( ) ;
1306
- foreach ( var tokenId in tokensOfOwner )
1259
+ for ( var i = 0 ; i < balanceOfOwner ; i ++ )
1307
1260
{
1308
- ownedNftTasks . Add ( contract . ERC721_GetNFT ( tokenId ) ) ;
1261
+ var tokenOfOwnerByIndex = await contract . ERC721_TokenOfOwnerByIndex ( owner , i ) . ConfigureAwait ( false ) ;
1262
+ if ( tokenOfOwnerByIndex >= startTokenId && tokenOfOwnerByIndex < startTokenId + count )
1263
+ {
1264
+ ownedNftTasks . Add ( contract . ERC721_GetNFT ( tokenOfOwnerByIndex ) ) ;
1265
+ }
1309
1266
}
1310
1267
var ownedNfts = await Task . WhenAll ( ownedNftTasks ) . ConfigureAwait ( false ) ;
1311
1268
return ownedNfts . ToList ( ) ;
1312
1269
}
1313
- catch
1270
+ catch ( Exception )
1314
1271
{
1315
- try
1272
+ var allNfts = await contract . ERC721_GetAllNFTs ( startTokenId , count ) . ConfigureAwait ( false ) ;
1273
+ var ownedNfts = new List < NFT > ( ) ;
1274
+ foreach ( var nft in allNfts )
1316
1275
{
1317
- // ERC721Enumerable
1318
- var balanceOfOwner = await contract . ERC721_BalanceOf ( owner ) . ConfigureAwait ( false ) ;
1319
- var ownedNftTasks = new List < Task < NFT > > ( ) ;
1320
- for ( var i = 0 ; i < balanceOfOwner ; i ++ )
1276
+ if ( nft . Owner == owner )
1321
1277
{
1322
- var tokenOfOwnerByIndex = await contract . ERC721_TokenOfOwnerByIndex ( owner , i ) . ConfigureAwait ( false ) ;
1323
- ownedNftTasks . Add ( contract . ERC721_GetNFT ( tokenOfOwnerByIndex ) ) ;
1278
+ ownedNfts . Add ( nft ) ;
1324
1279
}
1325
- var ownedNfts = await Task . WhenAll ( ownedNftTasks ) . ConfigureAwait ( false ) ;
1326
- return ownedNfts . ToList ( ) ;
1327
- }
1328
- catch ( Exception )
1329
- {
1330
- var allNfts = await contract . ERC721_GetAllNFTs ( ) . ConfigureAwait ( false ) ;
1331
- var ownedNfts = new List < NFT > ( ) ;
1332
- foreach ( var nft in allNfts )
1333
- {
1334
- if ( nft . Owner == owner )
1335
- {
1336
- ownedNfts . Add ( nft ) ;
1337
- }
1338
- }
1339
- return ownedNfts . ToList ( ) ;
1340
1280
}
1281
+ return ownedNfts . ToList ( ) ;
1341
1282
}
1342
1283
}
1343
1284
}
@@ -1384,21 +1325,16 @@ public static async Task<NFT> ERC1155_GetNFT(this ThirdwebContract contract, Big
1384
1325
/// </summary>
1385
1326
/// <param name="contract">The contract to interact with.</param>
1386
1327
/// <param name="startTokenId">The starting token ID (inclusive). Defaults to 0 if not specified.</param>
1387
- /// <param name="count">The number of tokens to retrieve. Defaults to the total supply if not specified.</param>
1328
+ /// <param name="count">The number of tokens to retrieve. Defaults to the 100 if not specified.</param>
1388
1329
/// <returns>A task representing the asynchronous operation, with a list of NFT results containing the token details.</returns>
1389
1330
/// <exception cref="ArgumentNullException">Thrown when the contract is null.</exception>
1390
- public static async Task < List < NFT > > ERC1155_GetAllNFTs ( this ThirdwebContract contract , BigInteger ? startTokenId = null , BigInteger ? count = null )
1331
+ public static async Task < List < NFT > > ERC1155_GetAllNFTs ( this ThirdwebContract contract , int startTokenId = 0 , int count = 100 )
1391
1332
{
1392
1333
if ( contract == null )
1393
1334
{
1394
1335
throw new ArgumentNullException ( nameof ( contract ) ) ;
1395
1336
}
1396
1337
1397
- if ( startTokenId == null )
1398
- {
1399
- startTokenId = 0 ;
1400
- }
1401
-
1402
1338
BigInteger totalSupply ;
1403
1339
try
1404
1340
{
@@ -1409,10 +1345,10 @@ public static async Task<List<NFT>> ERC1155_GetAllNFTs(this ThirdwebContract con
1409
1345
{
1410
1346
totalSupply = int . MaxValue ;
1411
1347
}
1412
- count = count == null ? totalSupply - startTokenId : Math . Min ( ( int ) count , ( int ) ( totalSupply - startTokenId ) ) ;
1348
+ count = Math . Min ( count , ( int ) ( totalSupply - startTokenId ) ) ;
1413
1349
1414
1350
var nftTasks = new List < Task < NFT > > ( ) ;
1415
- for ( var i = startTokenId . Value ; i < startTokenId . Value + count . Value ; i ++ )
1351
+ for ( var i = startTokenId ; i < startTokenId + count ; i ++ )
1416
1352
{
1417
1353
nftTasks . Add ( contract . ERC1155_GetNFT ( i ) ) ;
1418
1354
}
@@ -1427,11 +1363,11 @@ public static async Task<List<NFT>> ERC1155_GetAllNFTs(this ThirdwebContract con
1427
1363
/// <param name="contract">The contract to interact with.</param>
1428
1364
/// <param name="owner">The address of the owner.</param>
1429
1365
/// <param name="startTokenId">The starting token ID (inclusive). Defaults to 0 if not specified.</param>
1430
- /// <param name="count">The number of tokens to retrieve. Defaults to total supply if not specified.</param>
1366
+ /// <param name="count">The number of tokens to retrieve. Defaults to 100 if not specified.</param>
1431
1367
/// <returns>A task representing the asynchronous operation, with a list of NFT results containing the token details.</returns>
1432
1368
/// <exception cref="ArgumentNullException">Thrown when the contract is null.</exception>
1433
1369
/// <exception cref="ArgumentException">Thrown when the owner address is null or empty.</exception>
1434
- public static async Task < List < NFT > > ERC1155_GetOwnedNFTs ( this ThirdwebContract contract , string owner , BigInteger ? startTokenId = null , BigInteger ? count = null )
1370
+ public static async Task < List < NFT > > ERC1155_GetOwnedNFTs ( this ThirdwebContract contract , string owner , int startTokenId = 0 , int count = 100 )
1435
1371
{
1436
1372
if ( contract == null )
1437
1373
{
@@ -1443,11 +1379,6 @@ public static async Task<List<NFT>> ERC1155_GetOwnedNFTs(this ThirdwebContract c
1443
1379
throw new ArgumentException ( "Owner must be provided" ) ;
1444
1380
}
1445
1381
1446
- if ( startTokenId == null )
1447
- {
1448
- startTokenId = 0 ;
1449
- }
1450
-
1451
1382
BigInteger totalSupply ;
1452
1383
try
1453
1384
{
@@ -1458,12 +1389,12 @@ public static async Task<List<NFT>> ERC1155_GetOwnedNFTs(this ThirdwebContract c
1458
1389
{
1459
1390
totalSupply = int . MaxValue ;
1460
1391
}
1461
- count = count == null ? totalSupply - startTokenId : Math . Min ( ( int ) count , ( int ) ( totalSupply - startTokenId ) ) ;
1392
+ count = Math . Min ( count , ( int ) ( totalSupply - startTokenId ) ) ;
1462
1393
1463
1394
var ownerArray = new List < string > ( ) ;
1464
1395
var tokenIds = new List < BigInteger > ( ) ;
1465
1396
1466
- for ( var i = startTokenId . Value ; i < startTokenId . Value + count . Value ; i ++ )
1397
+ for ( var i = startTokenId ; i < startTokenId + count ; i ++ )
1467
1398
{
1468
1399
ownerArray . Add ( owner ) ;
1469
1400
tokenIds . Add ( i ) ;
0 commit comments