@@ -1177,9 +1177,10 @@ public static async Task<BigInteger> ERC1155_TotalSupply(this ThirdwebContract c
1177
1177
/// </summary>
1178
1178
/// <param name="contract">The contract to interact with.</param>
1179
1179
/// <param name="tokenId">The ID of the token.</param>
1180
+ /// <param name="fillOwner">A boolean indicating whether to fill the owner details. Defaults to true.</param>
1180
1181
/// <returns>A task representing the asynchronous operation, with an NFT result containing the token details.</returns>
1181
1182
/// <exception cref="ArgumentNullException">Thrown when the contract is null.</exception>
1182
- public static async Task < NFT > ERC721_GetNFT ( this ThirdwebContract contract , BigInteger tokenId )
1183
+ public static async Task < NFT > ERC721_GetNFT ( this ThirdwebContract contract , BigInteger tokenId , bool fillOwner = true )
1183
1184
{
1184
1185
if ( contract == null )
1185
1186
{
@@ -1198,14 +1199,17 @@ public static async Task<NFT> ERC721_GetNFT(this ThirdwebContract contract, BigI
1198
1199
}
1199
1200
metadata . Id = tokenId . ToString ( ) ;
1200
1201
1201
- string owner ;
1202
- try
1203
- {
1204
- owner = await contract . ERC721_OwnerOf ( tokenId ) . ConfigureAwait ( false ) ;
1205
- }
1206
- catch ( Exception )
1202
+ var owner = Constants . ADDRESS_ZERO ;
1203
+ if ( fillOwner )
1207
1204
{
1208
- owner = Constants . ADDRESS_ZERO ;
1205
+ try
1206
+ {
1207
+ owner = await contract . ERC721_OwnerOf ( tokenId ) . ConfigureAwait ( false ) ;
1208
+ }
1209
+ catch ( Exception )
1210
+ {
1211
+ owner = Constants . ADDRESS_ZERO ;
1212
+ }
1209
1213
}
1210
1214
1211
1215
return new NFT
@@ -1214,6 +1218,7 @@ public static async Task<NFT> ERC721_GetNFT(this ThirdwebContract contract, BigI
1214
1218
Owner = owner ,
1215
1219
Type = NFTType . ERC721 ,
1216
1220
Supply = 1 ,
1221
+ QuantityOwned = 1
1217
1222
} ;
1218
1223
}
1219
1224
@@ -1223,9 +1228,10 @@ public static async Task<NFT> ERC721_GetNFT(this ThirdwebContract contract, BigI
1223
1228
/// <param name="contract">The contract to interact with.</param>
1224
1229
/// <param name="startTokenId">The starting token ID (inclusive). Defaults to 0 if not specified.</param>
1225
1230
/// <param name="count">The number of tokens to retrieve. Defaults to 100 if not specified.</param>
1231
+ /// <param name="fillOwner">A boolean indicating whether to fill the owner details. Defaults to true.</param>
1226
1232
/// <returns>A task representing the asynchronous operation, with a list of NFT results containing the token details.</returns>
1227
1233
/// <exception cref="ArgumentNullException">Thrown when the contract is null.</exception>
1228
- public static async Task < List < NFT > > ERC721_GetAllNFTs ( this ThirdwebContract contract , int startTokenId = 0 , int count = 100 )
1234
+ public static async Task < List < NFT > > ERC721_GetAllNFTs ( this ThirdwebContract contract , int startTokenId = 0 , int count = 100 , bool fillOwner = true )
1229
1235
{
1230
1236
if ( contract == null )
1231
1237
{
@@ -1238,7 +1244,7 @@ public static async Task<List<NFT>> ERC721_GetAllNFTs(this ThirdwebContract cont
1238
1244
var nftTasks = new List < Task < NFT > > ( ) ;
1239
1245
for ( var i = startTokenId ; i < startTokenId + count ; i ++ )
1240
1246
{
1241
- nftTasks . Add ( contract . ERC721_GetNFT ( i ) ) ;
1247
+ nftTasks . Add ( contract . ERC721_GetNFT ( i , fillOwner ) ) ;
1242
1248
}
1243
1249
1244
1250
var allNfts = await Task . WhenAll ( nftTasks ) . ConfigureAwait ( false ) ;
@@ -1322,9 +1328,10 @@ public static async Task<List<NFT>> ERC721_GetOwnedNFTs(this ThirdwebContract co
1322
1328
/// </summary>
1323
1329
/// <param name="contract">The contract to interact with.</param>
1324
1330
/// <param name="tokenId">The ID of the token.</param>
1331
+ /// <param name="fillSupply">A boolean indicating whether to fill the supply. Defaults to true if not specified.</param>
1325
1332
/// <returns>A task representing the asynchronous operation, with an NFT result containing the token details.</returns>
1326
1333
/// <exception cref="ArgumentNullException">Thrown when the contract is null.</exception>
1327
- public static async Task < NFT > ERC1155_GetNFT ( this ThirdwebContract contract , BigInteger tokenId )
1334
+ public static async Task < NFT > ERC1155_GetNFT ( this ThirdwebContract contract , BigInteger tokenId , bool fillSupply = true )
1328
1335
{
1329
1336
if ( contract == null )
1330
1337
{
@@ -1342,21 +1349,24 @@ public static async Task<NFT> ERC1155_GetNFT(this ThirdwebContract contract, Big
1342
1349
metadata = new NFTMetadata { Description = e . Message } ;
1343
1350
}
1344
1351
metadata . Id = tokenId . ToString ( ) ;
1345
- var owner = string . Empty ;
1346
- BigInteger supply ;
1347
- try
1348
- {
1349
- supply = await contract . ERC1155_TotalSupply ( tokenId ) . ConfigureAwait ( false ) ;
1350
- }
1351
- catch ( Exception )
1352
+
1353
+ var supply = BigInteger . MinusOne ;
1354
+ if ( fillSupply )
1352
1355
{
1353
- supply = BigInteger . MinusOne ;
1356
+ try
1357
+ {
1358
+ supply = await contract . ERC1155_TotalSupply ( tokenId ) . ConfigureAwait ( false ) ;
1359
+ }
1360
+ catch ( Exception )
1361
+ {
1362
+ supply = BigInteger . MinusOne ;
1363
+ }
1354
1364
}
1355
1365
1356
1366
return new NFT
1357
1367
{
1358
1368
Metadata = metadata ,
1359
- Owner = owner ,
1369
+ Owner = "" ,
1360
1370
Type = NFTType . ERC1155 ,
1361
1371
Supply = supply ,
1362
1372
} ;
@@ -1368,31 +1378,32 @@ public static async Task<NFT> ERC1155_GetNFT(this ThirdwebContract contract, Big
1368
1378
/// <param name="contract">The contract to interact with.</param>
1369
1379
/// <param name="startTokenId">The starting token ID (inclusive). Defaults to 0 if not specified.</param>
1370
1380
/// <param name="count">The number of tokens to retrieve. Defaults to the 100 if not specified.</param>
1381
+ /// <param name="fillSupply">A boolean indicating whether to fill the supply. Defaults to true if not specified.</param>
1371
1382
/// <returns>A task representing the asynchronous operation, with a list of NFT results containing the token details.</returns>
1372
1383
/// <exception cref="ArgumentNullException">Thrown when the contract is null.</exception>
1373
- public static async Task < List < NFT > > ERC1155_GetAllNFTs ( this ThirdwebContract contract , int startTokenId = 0 , int count = 100 )
1384
+ public static async Task < List < NFT > > ERC1155_GetAllNFTs ( this ThirdwebContract contract , int startTokenId = 0 , int count = 100 , bool fillSupply = true )
1374
1385
{
1375
1386
if ( contract == null )
1376
1387
{
1377
1388
throw new ArgumentNullException ( nameof ( contract ) ) ;
1378
1389
}
1379
1390
1380
- BigInteger totalSupply ;
1391
+ BigInteger totalCount ;
1381
1392
try
1382
1393
{
1383
1394
// Not part of IERC1155 so we fallback just in case
1384
- totalSupply = await contract . ERC1155_TotalSupply ( ) . ConfigureAwait ( false ) ;
1395
+ totalCount = await contract . ERC1155_TotalSupply ( ) . ConfigureAwait ( false ) ;
1385
1396
}
1386
1397
catch
1387
1398
{
1388
- totalSupply = int . MaxValue ;
1399
+ totalCount = int . MaxValue ;
1389
1400
}
1390
- count = Math . Min ( count , ( int ) ( totalSupply - startTokenId ) ) ;
1401
+ count = Math . Min ( count , ( int ) ( totalCount - startTokenId ) ) ;
1391
1402
1392
1403
var nftTasks = new List < Task < NFT > > ( ) ;
1393
1404
for ( var i = startTokenId ; i < startTokenId + count ; i ++ )
1394
1405
{
1395
- nftTasks . Add ( contract . ERC1155_GetNFT ( i ) ) ;
1406
+ nftTasks . Add ( contract . ERC1155_GetNFT ( i , fillSupply ) ) ;
1396
1407
}
1397
1408
1398
1409
var allNfts = await Task . WhenAll ( nftTasks ) . ConfigureAwait ( false ) ;
@@ -1454,6 +1465,10 @@ public static async Task<List<NFT>> ERC1155_GetOwnedNFTs(this ThirdwebContract c
1454
1465
}
1455
1466
1456
1467
var ownerNfts = await Task . WhenAll ( ownerNftTasks ) . ConfigureAwait ( false ) ;
1468
+ for ( var i = 0 ; i < ownerNfts . Length ; i ++ )
1469
+ {
1470
+ ownerNfts [ i ] . QuantityOwned = balanceOfBatch [ i ] ;
1471
+ }
1457
1472
return ownerNfts . ToList ( ) ;
1458
1473
}
1459
1474
0 commit comments