Skip to content

Commit afd71be

Browse files
committed
nft loader swaps / fix getowned for drops
1 parent 7f818c0 commit afd71be

File tree

8 files changed

+254
-79
lines changed

8 files changed

+254
-79
lines changed

Assets/Thirdweb/Core/Scripts/ERC721.cs

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ public async Task<List<NFT>> GetAll(QueryAllParams queryParams = null)
101101
}
102102
catch (System.Exception e)
103103
{
104-
Debug.LogWarning($"Multicall failed, attempting normal calls. Error: {e.Message}");
105104
List<NFT> allNfts = new List<NFT>();
106105
for (int i = start; i < end; i++)
107106
allNfts.Add(await Get(i.ToString()));
@@ -129,21 +128,36 @@ public async Task<List<NFT>> GetOwned(string address = null)
129128
List<NFT> ownedNfts = await rawTokenData.ToNFTList();
130129
return ownedNfts;
131130
}
132-
catch (System.Exception e)
131+
catch (System.Exception)
133132
{
134-
Debug.LogWarning($"Multicall failed, likely not enumerable, attempting normal calls. Error: {e.Message}");
135-
136-
var balanceOfOwner = int.Parse(await BalanceOf(owner));
137-
List<NFT> ownedNfts = new List<NFT>();
138-
for (int i = 0; i < balanceOfOwner; i++)
133+
try
139134
{
140-
var tokenId = await TransactionManager.ThirdwebRead<TokenERC721Contract.TokenOfOwnerByIndexFunction, TokenERC721Contract.TokenOfOwnerByIndexOutputDTO>(
141-
contractAddress,
142-
new TokenERC721Contract.TokenOfOwnerByIndexFunction() { Owner = owner, Index = (BigInteger)i }
143-
);
144-
ownedNfts.Add(await Get(tokenId.ReturnValue1.ToString()));
135+
var balanceOfOwner = int.Parse(await BalanceOf(owner));
136+
List<NFT> ownedNfts = new List<NFT>();
137+
for (int i = 0; i < balanceOfOwner; i++)
138+
{
139+
var tokenId = await TransactionManager.ThirdwebRead<TokenERC721Contract.TokenOfOwnerByIndexFunction, TokenERC721Contract.TokenOfOwnerByIndexOutputDTO>(
140+
contractAddress,
141+
new TokenERC721Contract.TokenOfOwnerByIndexFunction() { Owner = owner, Index = (BigInteger)i }
142+
);
143+
ownedNfts.Add(await Get(tokenId.ReturnValue1.ToString()));
144+
}
145+
return ownedNfts;
146+
}
147+
catch (System.Exception)
148+
{
149+
var count = await TotalCount();
150+
151+
List<NFT> ownedNfts = new List<NFT>();
152+
for (int i = 0; i < count; i++)
153+
{
154+
if (await OwnerOf(i.ToString()) == owner)
155+
{
156+
ownedNfts.Add(await Get(i.ToString()));
157+
}
158+
}
159+
return ownedNfts;
145160
}
146-
return ownedNfts;
147161
}
148162
}
149163
}
@@ -159,11 +173,19 @@ public async Task<string> OwnerOf(string tokenId)
159173
}
160174
else
161175
{
162-
var tokenURI = await TransactionManager.ThirdwebRead<TokenERC721Contract.OwnerOfFunction, TokenERC721Contract.OwnerOfOutputDTO>(
163-
contractAddress,
164-
new TokenERC721Contract.OwnerOfFunction() { TokenId = BigInteger.Parse(tokenId) }
165-
);
166-
return tokenURI.ReturnValue1;
176+
try
177+
{
178+
var tokenURI = await TransactionManager.ThirdwebRead<TokenERC721Contract.OwnerOfFunction, TokenERC721Contract.OwnerOfOutputDTO>(
179+
contractAddress,
180+
new TokenERC721Contract.OwnerOfFunction() { TokenId = BigInteger.Parse(tokenId) }
181+
);
182+
return tokenURI.ReturnValue1;
183+
}
184+
catch (System.Exception)
185+
{
186+
Debug.LogWarning("$Unable to find owner of {tokenId}, return address(0)");
187+
return "0x0000000000000000000000000000000000000000";
188+
}
167189
}
168190
}
169191

Assets/Thirdweb/Core/Scripts/Types.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public struct NFTMetadata
1313
public string image;
1414
public string name;
1515
public string external_url;
16-
public string attributes;
16+
public object attributes;
1717

1818
public override string ToString()
1919
{
@@ -24,7 +24,7 @@ public override string ToString()
2424
+ $"\n>image: {image}"
2525
+ $"\n>name: {name}"
2626
+ $"\n>external_url: {external_url}"
27-
+ $"\n>attributes: {attributes}";
27+
+ $"\n>attributes: {attributes?.ToString()}";
2828
}
2929
}
3030

Assets/Thirdweb/Examples/Prefabs/Prefab_NFTLoader.prefab

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -389,24 +389,23 @@ MonoBehaviour:
389389
m_EditorClassIdentifier:
390390
query:
391391
loadOneNft:
392-
- contractAddress: 0x45c498Dfc0b4126605DD91eB1850fd6b5BCe9efC
392+
- contractAddress: 0x5350e0662D1BAB9f8843690B91C363aFD3e0cFe7
393393
tokenID: 2
394394
type: 0
395-
- contractAddress: 0x82c488a1BC64ab3b91B927380cca9Db7bF347879
395+
- contractAddress: 0x5350e0662D1BAB9f8843690B91C363aFD3e0cFe7
396396
tokenID: 1
397-
type: 1
397+
type: 0
398+
- contractAddress: 0x5350e0662D1BAB9f8843690B91C363aFD3e0cFe7
399+
tokenID: 0
400+
type: 0
398401
loadMultipleNfts:
399-
- contractAddress: 0x45c498Dfc0b4126605DD91eB1850fd6b5BCe9efC
400-
startID: 1
402+
- contractAddress: 0x5350e0662D1BAB9f8843690B91C363aFD3e0cFe7
403+
startID: 0
401404
count: 2
402405
type: 0
403-
- contractAddress: 0x82c488a1BC64ab3b91B927380cca9Db7bF347879
404-
startID: 1
405-
count: 1
406-
type: 1
407406
loadOwnedNfts:
408-
- contractAddress: 0x45c498Dfc0b4126605DD91eB1850fd6b5BCe9efC
409-
owner: 0xDaaBDaaC8073A7dAbdC96F6909E8476ab4001B34
407+
- contractAddress: 0x5350e0662D1BAB9f8843690B91C363aFD3e0cFe7
408+
owner: 0xa3841994009B4fEabb01ebcC62062F9E56F701CD
410409
type: 0
411410
contentParent: {fileID: 7702873693523111848}
412411
nftPrefab: {fileID: 7568917608122384971, guid: 41381d62941a9e74c92c44c6ff55ad50, type: 3}

Assets/Thirdweb/Examples/Prefabs/Prefab_Writing.prefab

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ MonoBehaviour:
636636
m_OnCullStateChanged:
637637
m_PersistentCalls:
638638
m_Calls: []
639-
m_text: Mint ERC1155
639+
m_text: Claim ERC1155
640640
m_isRightToLeft: 0
641641
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
642642
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
@@ -921,7 +921,7 @@ MonoBehaviour:
921921
m_OnCullStateChanged:
922922
m_PersistentCalls:
923923
m_Calls: []
924-
m_text: Mint ERC721
924+
m_text: Claim ERC721
925925
m_isRightToLeft: 0
926926
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
927927
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
@@ -1356,7 +1356,7 @@ MonoBehaviour:
13561356
m_OnCullStateChanged:
13571357
m_PersistentCalls:
13581358
m_Calls: []
1359-
m_text: Mint ERC20
1359+
m_text: Claim ERC20
13601360
m_isRightToLeft: 0
13611361
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
13621362
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}

0 commit comments

Comments
 (0)