From 1c135b0f65b0c9b80d29766be26b92360d4d5dc0 Mon Sep 17 00:00:00 2001 From: 0xFirekeeper <43042585+0xFirekeeper@users.noreply.github.com> Date: Fri, 7 Mar 2025 22:26:33 +0000 Subject: [PATCH] Improve .NET/Unity Documentation (#6438) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also adds Insight and Engine Closes TOOL-3570 --- ## PR-Codex overview This PR focuses on enhancing documentation and sidebar navigation for the Thirdweb .NET SDK, introducing new wallet integrations, and updating metadata and descriptions for clarity. ### Detailed summary - Updated `PrivateKeyWallet` description to markdown format. - Changed `title` in `nebula/quickstart` metadata. - Added utility functions description in `utils/page.mdx`. - Removed `Constants.DECIMALS_18`. - Added `EngineWallet` documentation with usage example. - Updated sidebar links for better organization and added new sections. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` --- .../app/dotnet/insight/quickstart/page.mdx | 98 +++++++++++++++++++ .../src/app/dotnet/nebula/quickstart/page.mdx | 4 +- apps/portal/src/app/dotnet/sidebar.tsx | 47 +++++++-- apps/portal/src/app/dotnet/utils/page.mdx | 8 +- .../wallets/providers/engine-wallet/page.mdx | 71 ++++++++++++++ .../wallets/providers/private-key/page.mdx | 2 +- apps/portal/src/app/unity/v5/sidebar.tsx | 40 +++++--- 7 files changed, 241 insertions(+), 29 deletions(-) create mode 100644 apps/portal/src/app/dotnet/insight/quickstart/page.mdx create mode 100644 apps/portal/src/app/dotnet/wallets/providers/engine-wallet/page.mdx diff --git a/apps/portal/src/app/dotnet/insight/quickstart/page.mdx b/apps/portal/src/app/dotnet/insight/quickstart/page.mdx new file mode 100644 index 00000000000..e95d29e933f --- /dev/null +++ b/apps/portal/src/app/dotnet/insight/quickstart/page.mdx @@ -0,0 +1,98 @@ +import { Details, createMetadata } from "@doc"; + +export const metadata = createMetadata({ + title: "ThirdwebInsight | Thirdweb .NET SDK", + description: + "Instantiate Insight to fetch all the blockchain data you can fathom.", +}); + +# [Insight](https://thirdweb.com/insight) Indexer .NET Integration +Insight is an extremely useful and performant tool to query blockchain data and can decorate it quite nicely too. + +Did you know that vitalik, on Ethereum, Polygon and Arbitrum alone owns 7811 ERC20s, 34,362 ERC721s and 2,818 ERC1155s? +Let's go through some examples! + +### Instantiation +```csharp +using Thirdweb.Indexer; + +// Create a ThirdwebInsight instance +var insight = await ThirdwebInsight.Create(client); +``` + +### Simple Filters +```csharp +// Setup some filters +var address = await Utils.GetAddressFromENS(client, "vitalik.eth"); +var chains = new BigInteger[] { 1, 137, 42161 }; +``` + +### Fetching all tokens owned by a given address +```csharp +// 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}"); +``` + +### Fetching a specific type of token owned by a given address +```csharp +// Fetch ERC20s only +var erc20Tokens = await insight.GetTokens_ERC20(address, chains); +Console.WriteLine($"ERC20 Tokens: {JsonConvert.SerializeObject(erc20Tokens, Formatting.Indented)}"); + +// Fetch ERC721s only +var erc721Tokens = await insight.GetTokens_ERC721(address, chains); +Console.WriteLine($"ERC721 Tokens: {JsonConvert.SerializeObject(erc721Tokens, Formatting.Indented)}"); + +// Fetch ERC1155s only +var erc1155Tokens = await insight.GetTokens_ERC1155(address, chains); +Console.WriteLine($"ERC1155 Tokens: {JsonConvert.SerializeObject(erc1155Tokens, Formatting.Indented)}"); +``` + +### Fetching Events +Note: most of these parameters are optional (and some are not showcased here) +```csharp +// 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)}"); +``` + +### Fetching Transactions +```csharp +// Fetch transactions (great amount of optional filters available) +var transactions = await insight.GetTransactions( + chainIds: new BigInteger[] { 1 }, // ethereum + contractAddress: "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d", // bored apes + 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 transactions +); +Console.WriteLine($"Transactions: {JsonConvert.SerializeObject(transactions, Formatting.Indented)}"); +``` + +### Fetching NFTs with Metadata +Insight can return rich NFT Metadata. Extensions can turn Insight results into familiar NFT objects. + +```csharp +// Fetch ERC721s with extra metadata returned +var erc721Tokens = await insight.GetTokens_ERC721(address, chains, withMetadata: true); + +// Use ToNFT or 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}"); +``` \ No newline at end of file diff --git a/apps/portal/src/app/dotnet/nebula/quickstart/page.mdx b/apps/portal/src/app/dotnet/nebula/quickstart/page.mdx index 0809e12122f..fbb5dbac692 100644 --- a/apps/portal/src/app/dotnet/nebula/quickstart/page.mdx +++ b/apps/portal/src/app/dotnet/nebula/quickstart/page.mdx @@ -1,9 +1,9 @@ import { Details, createMetadata } from "@doc"; export const metadata = createMetadata({ - title: "ThirdwebContract.Create | Thirdweb .NET SDK", + title: "ThirdwebNebula | Thirdweb .NET SDK", description: - "Instantiate a ThirdwebContract to interact with smart contracts.", + "Instantiate Nebula to interact with a blockchain-powered AI assistant.", }); # [Nebula AI](https://thirdweb.com/nebula) .NET Integration diff --git a/apps/portal/src/app/dotnet/sidebar.tsx b/apps/portal/src/app/dotnet/sidebar.tsx index cc7e48c45c4..653f4978097 100644 --- a/apps/portal/src/app/dotnet/sidebar.tsx +++ b/apps/portal/src/app/dotnet/sidebar.tsx @@ -23,6 +23,10 @@ const walletProviders: SidebarLink = (() => { name: "Private Key Wallet", href: `${parentSlug}/private-key`, }, + { + name: "Engine Wallet", + href: `${parentSlug}/engine-wallet`, + }, ], }; })(); @@ -195,7 +199,7 @@ const transactions: SidebarLink = { }; const pay: SidebarLink = { - name: "Pay", + name: "Payments", isCollapsible: false, links: [ { @@ -285,6 +289,9 @@ export const sidebar: SideBar = { }, ], }, + { + separator: true, + }, { name: "Core", isCollapsible: false, @@ -297,27 +304,50 @@ export const sidebar: SideBar = { name: "Storage", href: "/dotnet/storage", }, + { + name: "Utilities", + href: "/dotnet/utils", + }, ], }, + { + separator: true, + }, { name: "Wallets", isCollapsible: false, links: [walletProviders, walletActions], }, { - name: "Blockchain API", + separator: true, + }, + { + name: "Transactions", + isCollapsible: false, + links: [contracts, transactions], + }, + { + separator: true, + }, + { + name: "Indexer", isCollapsible: false, links: [ - contracts, - transactions, { - name: "Common Utils", - href: "/dotnet/utils", + name: "Quickstart", + href: "/dotnet/insight/quickstart", + }, + { + name: "Insight Full Reference", + href: "https://thirdweb-dev.github.io/dotnet/docs/Thirdweb.Indexer.ThirdwebInsight.html", }, ], }, { - name: "Nebula AI", + separator: true, + }, + { + name: "AI", isCollapsible: false, links: [ { @@ -330,6 +360,9 @@ export const sidebar: SideBar = { }, ], }, + { + separator: true, + }, pay, ], }; diff --git a/apps/portal/src/app/dotnet/utils/page.mdx b/apps/portal/src/app/dotnet/utils/page.mdx index 43985f0b1c6..44c1ddabc08 100644 --- a/apps/portal/src/app/dotnet/utils/page.mdx +++ b/apps/portal/src/app/dotnet/utils/page.mdx @@ -7,6 +7,8 @@ export const metadata = createMetadata({ # Utils +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). + ## Constants.ADDRESS_ZERO A `string` representing the zero address `0x0000000000000000000000000000000000000000`. @@ -19,12 +21,6 @@ A `string` representing the native token address `0xEeeeeEeeeEeEeeEeEeEeeEEEeeee Useful for passing the native token address (ETH or equivalent) to various functions. -## Constants.DECIMALS_18 - -A `double` representing the value `1000000000000000000`. - -Useful for converting values between different decimal places. - ## Constants.ENTRYPOINT_ADDRESS_V06 A `string` representing the entrypoint address for Account Abstraction 0.7.0 `0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789`. diff --git a/apps/portal/src/app/dotnet/wallets/providers/engine-wallet/page.mdx b/apps/portal/src/app/dotnet/wallets/providers/engine-wallet/page.mdx new file mode 100644 index 00000000000..841212e3d9b --- /dev/null +++ b/apps/portal/src/app/dotnet/wallets/providers/engine-wallet/page.mdx @@ -0,0 +1,71 @@ +import { Details, Callout, createMetadata } from "@doc"; + +export const metadata = createMetadata({ + title: "EngineWallet.Create | Thirdweb .NET SDK", + description: + "Instantiate a EngineWallet to sign transactions and messages.", +}); + +# EngineWallet.Create + +A .NET integration of thirdweb [Engine](https://thirdweb.com/engine). + +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. + +## Usage + +```csharp +// EngineWallet is compatible with IThirdwebWallet and can be used with any SDK method/extension +var engineWallet = await EngineWallet.Create( + client: client, + engineUrl: Environment.GetEnvironmentVariable("ENGINE_URL"), + authToken: Environment.GetEnvironmentVariable("ENGINE_ACCESS_TOKEN"), + walletAddress: Environment.GetEnvironmentVariable("ENGINE_BACKEND_WALLET_ADDRESS"), + timeoutSeconds: null, // no timeout + additionalHeaders: null // can set things like x-account-address if using basic session keys +); + +// Simple self transfer +var receipt = await engineWallet.Transfer(chainId: 11155111, toAddress: await engineWallet.GetAddress(), weiAmount: 0); +Console.WriteLine($"Receipt: {receipt}"); +``` + + + 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. + + +
+ +### client (required) + +An instance of `ThirdwebClient`. + +### engineUrl (required) + +The URL of the Thirdweb Engine instance, get it from your Engine dashboard. + +### authToken (required) + +The access token for the Engine instance, get it from your Engine dashboard. + +### walletAddress (required) + +The address of the backend wallet that will be used to sign transactions. You can create a backend wallet using the Engine dashboard. + +### timeoutSeconds (optional) + +Enforce a timeout for requests to the Engine instance, in seconds. + +### additionalHeaders (optional) + +Additional headers to include in requests to the Engine instance, such as `x-account-address` for Account Abstraction/Session Key flows. + +
+ +
+ +### EngineWallet + +Returns an instance of `EngineWallet`, ready to sign transactions and messages with the provided access token. + +
\ No newline at end of file diff --git a/apps/portal/src/app/dotnet/wallets/providers/private-key/page.mdx b/apps/portal/src/app/dotnet/wallets/providers/private-key/page.mdx index d026940ca16..5c5dc09096c 100644 --- a/apps/portal/src/app/dotnet/wallets/providers/private-key/page.mdx +++ b/apps/portal/src/app/dotnet/wallets/providers/private-key/page.mdx @@ -36,7 +36,7 @@ The private key of the wallet, provided as a hexadecimal `string`. This key gran
-PrivateKeyWallet +### PrivateKeyWallet Returns an instance of `PrivateKeyWallet`, ready to sign transactions and messages with the provided private key. diff --git a/apps/portal/src/app/unity/v5/sidebar.tsx b/apps/portal/src/app/unity/v5/sidebar.tsx index 8e2a5894bfe..681922e272d 100644 --- a/apps/portal/src/app/unity/v5/sidebar.tsx +++ b/apps/portal/src/app/unity/v5/sidebar.tsx @@ -1,5 +1,5 @@ import type { SideBar } from "@/components/Layouts/DocLayout"; -import { CodeIcon, ZapIcon } from "lucide-react"; +import { CodeIcon, ExternalLinkIcon, ZapIcon } from "lucide-react"; const sdkSlug = "/unity/v5"; const walletProvidersSlug = `${sdkSlug}/wallets`; @@ -23,6 +23,9 @@ export const sidebar: SideBar = { isCollapsible: false, icon: , }, + { + separator: true, + }, { name: "Core", isCollapsible: false, @@ -38,7 +41,10 @@ export const sidebar: SideBar = { ], }, { - name: "Wallets", + separator: true, + }, + { + name: "Onboarding Users", isCollapsible: false, links: [ { @@ -68,7 +74,10 @@ export const sidebar: SideBar = { ], }, { - name: "Blockchain API", + separator: true, + }, + { + name: "Onchain Interactions", isCollapsible: false, links: [ { @@ -82,25 +91,30 @@ export const sidebar: SideBar = { ], }, { - name: "Pay", - isCollapsible: false, - links: [ - { - name: ".NET SDK QuickStart", - href: "/dotnet/pay/quickstart", - }, - ], + separator: true, }, { - name: "Nebula AI", + name: "Advanced Functionality", isCollapsible: false, links: [ { - name: ".NET SDK QuickStart", + name: "Insight Indexer", + href: "/dotnet/insight/quickstart", + icon: , + }, + { + name: "Nebula AI", href: "/dotnet/nebula/quickstart", + icon: , + }, + { + name: "Payments", + href: "/dotnet/pay/quickstart", + icon: , }, ], }, + { separator: true }, { name: "Migrate from v4",