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
40 changes: 40 additions & 0 deletions Thirdweb.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Thirdweb;
using Thirdweb.AccountAbstraction;
using Thirdweb.AI;
using Thirdweb.Indexer;
using Thirdweb.Pay;

DotEnv.Load();
Expand Down Expand Up @@ -40,6 +41,45 @@

#endregion

#region Indexer

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

// // Setup some filters
// var address = await Utils.GetAddressFromENS(client, "vitalik.eth");
// var chains = new BigInteger[] { 1, 137, 42161 };

// // Fetch all token types
// var tokens = await insight.GetTokens(address, chains);
// Console.WriteLine($"ERC20 Count: {tokens.erc20Tokens.Length} | ERC721 Count: {tokens.erc721Tokens.Length} | ERC1155 Count: {tokens.erc1155Tokens.Length}");

// // Fetch specific token types
// var erc20Tokens = await insight.GetTokens_ERC20(address, chains);
// Console.WriteLine($"ERC20 Tokens: {JsonConvert.SerializeObject(erc20Tokens, Formatting.Indented)}");

// // Fetch specific token types
// var erc721Tokens = await insight.GetTokens_ERC721(address, chains);
// Console.WriteLine($"ERC721 Tokens: {JsonConvert.SerializeObject(erc721Tokens, Formatting.Indented)}");

// // Fetch specific token types
// var erc1155Tokens = await insight.GetTokens_ERC1155(address, chains);
// Console.WriteLine($"ERC1155 Tokens: {JsonConvert.SerializeObject(erc1155Tokens, Formatting.Indented)}");

// // Fetch events (great amount of optional filters available)
// var events = await insight.GetEvents(
// chainIds: new BigInteger[] { 1 }, // ethereum
// contractAddress: "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d", // bored apes
// eventSignature: "Transfer(address,address,uint256)", // transfer event
// fromTimestamp: Utils.GetUnixTimeStampNow() - 3600, // last hour
// sortBy: SortBy.TransactionIndex, // block number, block timestamp or transaction index
// sortOrder: SortOrder.Desc, // latest first
// limit: 5 // last 5 transfers
// );
// Console.WriteLine($"Events: {JsonConvert.SerializeObject(events, Formatting.Indented)}");

#endregion

#region AI

// // Prepare some context
Expand Down
121 changes: 121 additions & 0 deletions Thirdweb/Thirdweb.Indexer/ThirdwebInsight.Types.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
using System.Numerics;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Thirdweb.Indexer;

/// <summary>
/// Represents the response model wrapping the result of an API call.
/// </summary>
/// <typeparam name="T">The type of the result.</typeparam>
internal class ResponseModel<T>
{
/// <summary>
/// The result returned by the API.
/// </summary>
[JsonProperty("data")]
internal T[] Data { get; set; }

[JsonProperty("aggregations")]
public object Aggregations { get; set; } = null!;

[JsonProperty("meta")]
public Meta Meta { get; set; } = null!;
}

public class Token
{
[JsonProperty("chainId", Required = Required.Always)]
public BigInteger ChainId { get; set; }

[JsonProperty("balance", Required = Required.Always)]
public BigInteger Balance { get; set; }

[JsonProperty("tokenAddress", Required = Required.Always)]
public string TokenAddress { get; set; }
}

public class Token_ERC20 : Token { }

public class Token_ERC721 : Token { }

public class Token_ERC1155 : Token
{
[JsonProperty("tokenId", Required = Required.Always)]
public BigInteger TokenId { get; set; }
}

public class Event
{
[JsonProperty("chain_id")]
public BigInteger ChainId { get; set; }

[JsonProperty("block_number")]
public string BlockNumber { get; set; } = null!;

[JsonProperty("block_hash")]
public string BlockHash { get; set; } = null!;

[JsonProperty("block_timestamp")]
public string BlockTimestamp { get; set; } = null!;

[JsonProperty("transaction_hash")]
public string TransactionHash { get; set; } = null!;

[JsonProperty("transaction_index")]
public BigInteger TransactionIndex { get; set; }

[JsonProperty("log_index")]
public BigInteger LogIndex { get; set; }

[JsonProperty("address")]
public string Address { get; set; } = null!;

[JsonProperty("data")]
public string Data { get; set; } = null!;

[JsonProperty("topics")]
public List<string> Topics { get; set; } = new();

[JsonProperty("decoded")]
public Decoded Decoded { get; set; } = null!;
}

public class Decoded
{
[JsonProperty("name")]
public string Name { get; set; } = null!;

[JsonProperty("signature")]
public string Signature { get; set; } = null!;

[JsonProperty("indexedParams")]
public JObject IndexedParams { get; set; } = new();

[JsonProperty("nonIndexedParams")]
public JObject NonIndexedParams { get; set; } = new();
}

public class Meta
{
[JsonProperty("chain_ids", Required = Required.Always)]
public List<BigInteger> ChainIds { get; set; } = new();

[JsonProperty("address")]
public string Address { get; set; }

[JsonProperty("signature")]
public string Signature { get; set; }

[JsonProperty("page", Required = Required.Always)]
public BigInteger Page { get; set; }

[JsonProperty("limit_per_chain", Required = Required.Always)]
public BigInteger LimitPerChain { get; set; }

[JsonProperty("total_items", Required = Required.Always)]
public BigInteger TotalItems { get; set; }

[JsonProperty("total_pages", Required = Required.Always)]
public BigInteger TotalPages { get; set; }
}
Loading