Skip to content

Commit 4dc98bc

Browse files
authored
Thirdweb Insight Integration (#133)
1 parent c58f47a commit 4dc98bc

File tree

4 files changed

+425
-0
lines changed

4 files changed

+425
-0
lines changed

Thirdweb.Console/Program.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using Thirdweb;
1414
using Thirdweb.AccountAbstraction;
1515
using Thirdweb.AI;
16+
using Thirdweb.Indexer;
1617
using Thirdweb.Pay;
1718

1819
DotEnv.Load();
@@ -40,6 +41,45 @@
4041

4142
#endregion
4243

44+
#region Indexer
45+
46+
// // Create a ThirdwebInsight instance
47+
// var insight = await ThirdwebInsight.Create(client);
48+
49+
// // Setup some filters
50+
// var address = await Utils.GetAddressFromENS(client, "vitalik.eth");
51+
// var chains = new BigInteger[] { 1, 137, 42161 };
52+
53+
// // Fetch all token types
54+
// var tokens = await insight.GetTokens(address, chains);
55+
// Console.WriteLine($"ERC20 Count: {tokens.erc20Tokens.Length} | ERC721 Count: {tokens.erc721Tokens.Length} | ERC1155 Count: {tokens.erc1155Tokens.Length}");
56+
57+
// // Fetch specific token types
58+
// var erc20Tokens = await insight.GetTokens_ERC20(address, chains);
59+
// Console.WriteLine($"ERC20 Tokens: {JsonConvert.SerializeObject(erc20Tokens, Formatting.Indented)}");
60+
61+
// // Fetch specific token types
62+
// var erc721Tokens = await insight.GetTokens_ERC721(address, chains);
63+
// Console.WriteLine($"ERC721 Tokens: {JsonConvert.SerializeObject(erc721Tokens, Formatting.Indented)}");
64+
65+
// // Fetch specific token types
66+
// var erc1155Tokens = await insight.GetTokens_ERC1155(address, chains);
67+
// Console.WriteLine($"ERC1155 Tokens: {JsonConvert.SerializeObject(erc1155Tokens, Formatting.Indented)}");
68+
69+
// // Fetch events (great amount of optional filters available)
70+
// var events = await insight.GetEvents(
71+
// chainIds: new BigInteger[] { 1 }, // ethereum
72+
// contractAddress: "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d", // bored apes
73+
// eventSignature: "Transfer(address,address,uint256)", // transfer event
74+
// fromTimestamp: Utils.GetUnixTimeStampNow() - 3600, // last hour
75+
// sortBy: SortBy.TransactionIndex, // block number, block timestamp or transaction index
76+
// sortOrder: SortOrder.Desc, // latest first
77+
// limit: 5 // last 5 transfers
78+
// );
79+
// Console.WriteLine($"Events: {JsonConvert.SerializeObject(events, Formatting.Indented)}");
80+
81+
#endregion
82+
4383
#region AI
4484

4585
// // Prepare some context
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
using System.Numerics;
2+
using Newtonsoft.Json;
3+
using Newtonsoft.Json.Linq;
4+
5+
namespace Thirdweb.Indexer;
6+
7+
/// <summary>
8+
/// Represents the response model wrapping the result of an API call.
9+
/// </summary>
10+
/// <typeparam name="T">The type of the result.</typeparam>
11+
internal class ResponseModel<T>
12+
{
13+
/// <summary>
14+
/// The result returned by the API.
15+
/// </summary>
16+
[JsonProperty("data")]
17+
internal T[] Data { get; set; }
18+
19+
[JsonProperty("aggregations")]
20+
public object Aggregations { get; set; } = null!;
21+
22+
[JsonProperty("meta")]
23+
public Meta Meta { get; set; } = null!;
24+
}
25+
26+
public class Token
27+
{
28+
[JsonProperty("chainId", Required = Required.Always)]
29+
public BigInteger ChainId { get; set; }
30+
31+
[JsonProperty("balance", Required = Required.Always)]
32+
public BigInteger Balance { get; set; }
33+
34+
[JsonProperty("tokenAddress", Required = Required.Always)]
35+
public string TokenAddress { get; set; }
36+
}
37+
38+
public class Token_ERC20 : Token { }
39+
40+
public class Token_ERC721 : Token { }
41+
42+
public class Token_ERC1155 : Token
43+
{
44+
[JsonProperty("tokenId", Required = Required.Always)]
45+
public BigInteger TokenId { get; set; }
46+
}
47+
48+
public class Event
49+
{
50+
[JsonProperty("chain_id")]
51+
public BigInteger ChainId { get; set; }
52+
53+
[JsonProperty("block_number")]
54+
public string BlockNumber { get; set; } = null!;
55+
56+
[JsonProperty("block_hash")]
57+
public string BlockHash { get; set; } = null!;
58+
59+
[JsonProperty("block_timestamp")]
60+
public string BlockTimestamp { get; set; } = null!;
61+
62+
[JsonProperty("transaction_hash")]
63+
public string TransactionHash { get; set; } = null!;
64+
65+
[JsonProperty("transaction_index")]
66+
public BigInteger TransactionIndex { get; set; }
67+
68+
[JsonProperty("log_index")]
69+
public BigInteger LogIndex { get; set; }
70+
71+
[JsonProperty("address")]
72+
public string Address { get; set; } = null!;
73+
74+
[JsonProperty("data")]
75+
public string Data { get; set; } = null!;
76+
77+
[JsonProperty("topics")]
78+
public List<string> Topics { get; set; } = new();
79+
80+
[JsonProperty("decoded")]
81+
public Decoded Decoded { get; set; } = null!;
82+
}
83+
84+
public class Decoded
85+
{
86+
[JsonProperty("name")]
87+
public string Name { get; set; } = null!;
88+
89+
[JsonProperty("signature")]
90+
public string Signature { get; set; } = null!;
91+
92+
[JsonProperty("indexedParams")]
93+
public JObject IndexedParams { get; set; } = new();
94+
95+
[JsonProperty("nonIndexedParams")]
96+
public JObject NonIndexedParams { get; set; } = new();
97+
}
98+
99+
public class Meta
100+
{
101+
[JsonProperty("chain_ids", Required = Required.Always)]
102+
public List<BigInteger> ChainIds { get; set; } = new();
103+
104+
[JsonProperty("address")]
105+
public string Address { get; set; }
106+
107+
[JsonProperty("signature")]
108+
public string Signature { get; set; }
109+
110+
[JsonProperty("page", Required = Required.Always)]
111+
public BigInteger Page { get; set; }
112+
113+
[JsonProperty("limit_per_chain", Required = Required.Always)]
114+
public BigInteger LimitPerChain { get; set; }
115+
116+
[JsonProperty("total_items", Required = Required.Always)]
117+
public BigInteger TotalItems { get; set; }
118+
119+
[JsonProperty("total_pages", Required = Required.Always)]
120+
public BigInteger TotalPages { get; set; }
121+
}

0 commit comments

Comments
 (0)