Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions Thirdweb.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@

#region Indexer

// Create a ThirdwebInsight instance
var insight = await ThirdwebInsight.Create(client);
// // Create a ThirdwebInsight instance
// var insight = await ThirdwebInsight.Create(client);

// // Setup some filters
// var address = await Utils.GetAddressFromENS(client, "vitalik.eth");
Expand Down Expand Up @@ -89,6 +89,17 @@
// );
// Console.WriteLine($"Transactions: {JsonConvert.SerializeObject(transactions, Formatting.Indented)}");

// // Use ToNFT to ToNFTList extensions
// var convertedNft = erc721Tokens[0].ToNFT();

// var convertedNfts = erc721Tokens.ToNFTList();

// // Use NFT Extensions (GetNFTImageBytes, or GetNFTSprite in Unity)
// var imageBytes = await convertedNft.GetNFTImageBytes(client);
// var pathToSave = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "nft.png");
// await File.WriteAllBytesAsync(pathToSave, imageBytes);
// Console.WriteLine($"NFT image saved to: {pathToSave}");

#endregion

#region AI
Expand Down
8 changes: 8 additions & 0 deletions Thirdweb/Thirdweb.Extensions/ThirdwebExtensions.Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public enum NFTType
/// Represents an NFT with metadata, owner, type, and supply information.
/// </summary>
[Serializable]
[JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)]
public struct NFT
{
/// <summary>
Expand Down Expand Up @@ -181,6 +182,7 @@ public struct NFT
/// Represents the metadata of an NFT.
/// </summary>
[Serializable]
[JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)]
public struct NFTMetadata
{
/// <summary>
Expand Down Expand Up @@ -213,6 +215,12 @@ public struct NFTMetadata
[JsonProperty("name")]
public string Name { get; set; }

/// <summary>
/// Gets or sets the video URL of the NFT.
/// </summary>
[JsonProperty("video_url")]
public string VideoUrl { get; set; }

/// <summary>
/// Gets or sets the animation URL of the NFT.
/// </summary>
Expand Down
45 changes: 45 additions & 0 deletions Thirdweb/Thirdweb.Indexer/ThirdwebInsight.Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
namespace Thirdweb.Indexer;

public static class ThirdwebInsightExtensions
{
public static NFT ToNFT(this Token_NFT token)
{
if (token == null)
{
return new NFT();
}

return new NFT()
{
Type = token.Contract?.Type switch
{
"ERC721" => NFTType.ERC721,
"ERC1155" => NFTType.ERC1155,
_ => throw new Exception($"Unknown NFT type: {token.Contract.Type}")
},
Metadata = new NFTMetadata()
{
Id = token.TokenId,
Description = token.Description,
Image = token.ImageUrl,
Name = token.Name,
VideoUrl = token.VideoUrl,
AnimationUrl = token.AnimationUrl,
ExternalUrl = token.ExternalUrl,
BackgroundColor = token.BackgroundColor,
Attributes = token.ExtraMetadata?.Attributes,
Properties = token.ExtraMetadata?.Properties,
}
};
}

public static List<NFT> ToNFTList(this IEnumerable<Token_NFT> tokens)
{
if (tokens == null)
{
return new List<NFT>();
}

return tokens.Select(token => token.ToNFT()).ToList();
}
}
Loading