Skip to content

Commit 0d7ab4f

Browse files
committed
Improve .NET/Unity Documentation
Also adds Insight and Engine Closes TOOL-3570
1 parent efceadd commit 0d7ab4f

File tree

7 files changed

+241
-29
lines changed

7 files changed

+241
-29
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import { Details, createMetadata } from "@doc";
2+
3+
export const metadata = createMetadata({
4+
title: "ThirdwebInsight | Thirdweb .NET SDK",
5+
description:
6+
"Instantiate Insight to fetch all the blockchain data you can fathom.",
7+
});
8+
9+
# [Insight](https://thirdweb.com/insight) Indexer .NET Integration
10+
Insight is an extremely useful and performant tool to query blockchain data and can decorate it quite nicely too.
11+
12+
Did you know that vitalik, on Ethereum, Polygon and Arbitrum alone owns 7811 ERC20s, 34,362 ERC721s and 2,818 ERC1155s?
13+
Let's go through some examples!
14+
15+
### Instantiation
16+
```csharp
17+
using Thirdweb.Indexer;
18+
19+
// Create a ThirdwebInsight instance
20+
var insight = await ThirdwebInsight.Create(client);
21+
```
22+
23+
### Simple Filters
24+
```csharp
25+
// Setup some filters
26+
var address = await Utils.GetAddressFromENS(client, "vitalik.eth");
27+
var chains = new BigInteger[] { 1, 137, 42161 };
28+
```
29+
30+
### Fetching all tokens owned by a given address
31+
```csharp
32+
// Fetch all token types
33+
var tokens = await insight.GetTokens(address, chains);
34+
Console.WriteLine($"ERC20 Count: {tokens.erc20Tokens.Length} | ERC721 Count: {tokens.erc721Tokens.Length} | ERC1155 Count: {tokens.erc1155Tokens.Length}");
35+
```
36+
37+
### Fetching a specific type of token owned by a given address
38+
```csharp
39+
// Fetch ERC20s only
40+
var erc20Tokens = await insight.GetTokens_ERC20(address, chains);
41+
Console.WriteLine($"ERC20 Tokens: {JsonConvert.SerializeObject(erc20Tokens, Formatting.Indented)}");
42+
43+
// Fetch ERC721s only
44+
var erc721Tokens = await insight.GetTokens_ERC721(address, chains);
45+
Console.WriteLine($"ERC721 Tokens: {JsonConvert.SerializeObject(erc721Tokens, Formatting.Indented)}");
46+
47+
// Fetch ERC1155s only
48+
var erc1155Tokens = await insight.GetTokens_ERC1155(address, chains);
49+
Console.WriteLine($"ERC1155 Tokens: {JsonConvert.SerializeObject(erc1155Tokens, Formatting.Indented)}");
50+
```
51+
52+
### Fetching Events
53+
Note: most of these parameters are optional (and some are not showcased here)
54+
```csharp
55+
// Fetch events (great amount of optional filters available)
56+
var events = await insight.GetEvents(
57+
chainIds: new BigInteger[] { 1 }, // ethereum
58+
contractAddress: "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d", // bored apes
59+
eventSignature: "Transfer(address,address,uint256)", // transfer event
60+
fromTimestamp: Utils.GetUnixTimeStampNow() - 3600, // last hour
61+
sortBy: SortBy.TransactionIndex, // block number, block timestamp or transaction index
62+
sortOrder: SortOrder.Desc, // latest first
63+
limit: 5 // last 5 transfers
64+
);
65+
Console.WriteLine($"Events: {JsonConvert.SerializeObject(events, Formatting.Indented)}");
66+
```
67+
68+
### Fetching Transactions
69+
```csharp
70+
// Fetch transactions (great amount of optional filters available)
71+
var transactions = await insight.GetTransactions(
72+
chainIds: new BigInteger[] { 1 }, // ethereum
73+
contractAddress: "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d", // bored apes
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 transactions
78+
);
79+
Console.WriteLine($"Transactions: {JsonConvert.SerializeObject(transactions, Formatting.Indented)}");
80+
```
81+
82+
### Fetching NFTs with Metadata
83+
Insight can return rich NFT Metadata. Extensions can turn Insight results into familiar NFT objects.
84+
85+
```csharp
86+
// Fetch ERC721s with extra metadata returned
87+
var erc721Tokens = await insight.GetTokens_ERC721(address, chains, withMetadata: true);
88+
89+
// Use ToNFT or ToNFTList extensions
90+
var convertedNft = erc721Tokens[0].ToNFT();
91+
var convertedNfts = erc721Tokens.ToNFTList();
92+
93+
// Use NFT Extensions (GetNFTImageBytes, or GetNFTSprite in Unity)
94+
var imageBytes = await convertedNft.GetNFTImageBytes(client);
95+
var pathToSave = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "nft.png");
96+
await File.WriteAllBytesAsync(pathToSave, imageBytes);
97+
Console.WriteLine($"NFT image saved to: {pathToSave}");
98+
```

apps/portal/src/app/dotnet/nebula/quickstart/page.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Details, createMetadata } from "@doc";
22

33
export const metadata = createMetadata({
4-
title: "ThirdwebContract.Create | Thirdweb .NET SDK",
4+
title: "ThirdwebNebula | Thirdweb .NET SDK",
55
description:
6-
"Instantiate a ThirdwebContract to interact with smart contracts.",
6+
"Instantiate Nebula to interact with a blockchain-powered AI assistant.",
77
});
88

99
# [Nebula AI](https://thirdweb.com/nebula) .NET Integration

apps/portal/src/app/dotnet/sidebar.tsx

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ const walletProviders: SidebarLink = (() => {
2323
name: "Private Key Wallet",
2424
href: `${parentSlug}/private-key`,
2525
},
26+
{
27+
name: "Engine Wallet",
28+
href: `${parentSlug}/engine-wallet`,
29+
},
2630
],
2731
};
2832
})();
@@ -195,7 +199,7 @@ const transactions: SidebarLink = {
195199
};
196200

197201
const pay: SidebarLink = {
198-
name: "Pay",
202+
name: "Payments",
199203
isCollapsible: false,
200204
links: [
201205
{
@@ -285,6 +289,9 @@ export const sidebar: SideBar = {
285289
},
286290
],
287291
},
292+
{
293+
separator: true,
294+
},
288295
{
289296
name: "Core",
290297
isCollapsible: false,
@@ -297,27 +304,50 @@ export const sidebar: SideBar = {
297304
name: "Storage",
298305
href: "/dotnet/storage",
299306
},
307+
{
308+
name: "Utilities",
309+
href: "/dotnet/utils",
310+
},
300311
],
301312
},
313+
{
314+
separator: true,
315+
},
302316
{
303317
name: "Wallets",
304318
isCollapsible: false,
305319
links: [walletProviders, walletActions],
306320
},
307321
{
308-
name: "Blockchain API",
322+
separator: true,
323+
},
324+
{
325+
name: "Transactions",
326+
isCollapsible: false,
327+
links: [contracts, transactions],
328+
},
329+
{
330+
separator: true,
331+
},
332+
{
333+
name: "Indexer",
309334
isCollapsible: false,
310335
links: [
311-
contracts,
312-
transactions,
313336
{
314-
name: "Common Utils",
315-
href: "/dotnet/utils",
337+
name: "Quickstart",
338+
href: "/dotnet/insight/quickstart",
339+
},
340+
{
341+
name: "Insight Full Reference",
342+
href: "https://thirdweb-dev.github.io/dotnet/docs/Thirdweb.Indexer.ThirdwebInsight.html",
316343
},
317344
],
318345
},
319346
{
320-
name: "Nebula AI",
347+
separator: true,
348+
},
349+
{
350+
name: "AI",
321351
isCollapsible: false,
322352
links: [
323353
{
@@ -330,6 +360,9 @@ export const sidebar: SideBar = {
330360
},
331361
],
332362
},
363+
{
364+
separator: true,
365+
},
333366
pay,
334367
],
335368
};

apps/portal/src/app/dotnet/utils/page.mdx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export const metadata = createMetadata({
77

88
# Utils
99

10+
A collection of common utility functions that are useful for interacting with the Thirdweb .NET SDK or the blockchain in general. Full list available [here](https://thirdweb-dev.github.io/dotnet/docs/Thirdweb.Utils.html).
11+
1012
## Constants.ADDRESS_ZERO
1113

1214
A `string` representing the zero address `0x0000000000000000000000000000000000000000`.
@@ -19,12 +21,6 @@ A `string` representing the native token address `0xEeeeeEeeeEeEeeEeEeEeeEEEeeee
1921

2022
Useful for passing the native token address (ETH or equivalent) to various functions.
2123

22-
## Constants.DECIMALS_18
23-
24-
A `double` representing the value `1000000000000000000`.
25-
26-
Useful for converting values between different decimal places.
27-
2824
## Constants.ENTRYPOINT_ADDRESS_V06
2925

3026
A `string` representing the entrypoint address for Account Abstraction 0.7.0 `0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789`.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { Details, Callout, createMetadata } from "@doc";
2+
3+
export const metadata = createMetadata({
4+
title: "EngineWallet.Create | Thirdweb .NET SDK",
5+
description:
6+
"Instantiate a EngineWallet to sign transactions and messages.",
7+
});
8+
9+
# EngineWallet.Create
10+
11+
A .NET integration of thirdweb [Engine](https://thirdweb.com/engine).
12+
13+
Instantiate a `Engine` with a given private key. This wallet is capable of signing transactions and messages, interacting with smart contracts, and performing other blockchain operations. **This wallet type is intended for backend applications only,** due to the sensitive nature of private keys.
14+
15+
## Usage
16+
17+
```csharp
18+
// EngineWallet is compatible with IThirdwebWallet and can be used with any SDK method/extension
19+
var engineWallet = await EngineWallet.Create(
20+
client: client,
21+
engineUrl: Environment.GetEnvironmentVariable("ENGINE_URL"),
22+
authToken: Environment.GetEnvironmentVariable("ENGINE_ACCESS_TOKEN"),
23+
walletAddress: Environment.GetEnvironmentVariable("ENGINE_BACKEND_WALLET_ADDRESS"),
24+
timeoutSeconds: null, // no timeout
25+
additionalHeaders: null // can set things like x-account-address if using basic session keys
26+
);
27+
28+
// Simple self transfer
29+
var receipt = await engineWallet.Transfer(chainId: 11155111, toAddress: await engineWallet.GetAddress(), weiAmount: 0);
30+
Console.WriteLine($"Receipt: {receipt}");
31+
```
32+
33+
<Callout variant="warning" title="Important">
34+
This method involves using an access token, it is meant to be used in a secure backend environment. Never expose access tokens in client-side code or store them in an insecure manner. Ideally, use environment variables or secure vaults to manage access tokens in backend services.
35+
</Callout>
36+
37+
<Details summary="Parameters">
38+
39+
### client (required)
40+
41+
An instance of `ThirdwebClient`.
42+
43+
### engineUrl (required)
44+
45+
The URL of the Thirdweb Engine instance, get it from your Engine dashboard.
46+
47+
### authToken (required)
48+
49+
The access token for the Engine instance, get it from your Engine dashboard.
50+
51+
### walletAddress (required)
52+
53+
The address of the backend wallet that will be used to sign transactions. You can create a backend wallet using the Engine dashboard.
54+
55+
### timeoutSeconds (optional)
56+
57+
Enforce a timeout for requests to the Engine instance, in seconds.
58+
59+
### additionalHeaders (optional)
60+
61+
Additional headers to include in requests to the Engine instance, such as `x-account-address` for Account Abstraction/Session Key flows.
62+
63+
</Details>
64+
65+
<Details summary="Return Value">
66+
67+
### EngineWallet
68+
69+
Returns an instance of `EngineWallet`, ready to sign transactions and messages with the provided access token.
70+
71+
</Details>

apps/portal/src/app/dotnet/wallets/providers/private-key/page.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ The private key of the wallet, provided as a hexadecimal `string`. This key gran
3636
</Details>
3737

3838
<Details summary="Return Value">
39-
PrivateKeyWallet
39+
### PrivateKeyWallet
4040

4141
Returns an instance of `PrivateKeyWallet`, ready to sign transactions and messages with the provided private key.
4242

apps/portal/src/app/unity/v5/sidebar.tsx

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { SideBar } from "@/components/Layouts/DocLayout";
2-
import { CodeIcon, ZapIcon } from "lucide-react";
2+
import { CodeIcon, ExternalLinkIcon, ZapIcon } from "lucide-react";
33

44
const sdkSlug = "/unity/v5";
55
const walletProvidersSlug = `${sdkSlug}/wallets`;
@@ -23,6 +23,9 @@ export const sidebar: SideBar = {
2323
isCollapsible: false,
2424
icon: <CodeIcon />,
2525
},
26+
{
27+
separator: true,
28+
},
2629
{
2730
name: "Core",
2831
isCollapsible: false,
@@ -38,7 +41,10 @@ export const sidebar: SideBar = {
3841
],
3942
},
4043
{
41-
name: "Wallets",
44+
separator: true,
45+
},
46+
{
47+
name: "Onboarding Users",
4248
isCollapsible: false,
4349
links: [
4450
{
@@ -68,7 +74,10 @@ export const sidebar: SideBar = {
6874
],
6975
},
7076
{
71-
name: "Blockchain API",
77+
separator: true,
78+
},
79+
{
80+
name: "Onchain Interactions",
7281
isCollapsible: false,
7382
links: [
7483
{
@@ -82,25 +91,30 @@ export const sidebar: SideBar = {
8291
],
8392
},
8493
{
85-
name: "Pay",
86-
isCollapsible: false,
87-
links: [
88-
{
89-
name: ".NET SDK QuickStart",
90-
href: "/dotnet/pay/quickstart",
91-
},
92-
],
94+
separator: true,
9395
},
9496
{
95-
name: "Nebula AI",
97+
name: "Advanced Functionality",
9698
isCollapsible: false,
9799
links: [
98100
{
99-
name: ".NET SDK QuickStart",
101+
name: "Insight Indexer",
102+
href: "/dotnet/insight/quickstart",
103+
icon: <ExternalLinkIcon />,
104+
},
105+
{
106+
name: "Nebula AI",
100107
href: "/dotnet/nebula/quickstart",
108+
icon: <ExternalLinkIcon />,
109+
},
110+
{
111+
name: "Payments",
112+
href: "/dotnet/pay/quickstart",
113+
icon: <ExternalLinkIcon />,
101114
},
102115
],
103116
},
117+
104118
{ separator: true },
105119
{
106120
name: "Migrate from v4",

0 commit comments

Comments
 (0)