Skip to content

Improve .NET/Unity Documentation #6438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 7, 2025
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
98 changes: 98 additions & 0 deletions apps/portal/src/app/dotnet/insight/quickstart/page.mdx
Original file line number Diff line number Diff line change
@@ -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}");
```
4 changes: 2 additions & 2 deletions apps/portal/src/app/dotnet/nebula/quickstart/page.mdx
Original file line number Diff line number Diff line change
@@ -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
Expand Down
47 changes: 40 additions & 7 deletions apps/portal/src/app/dotnet/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ const walletProviders: SidebarLink = (() => {
name: "Private Key Wallet",
href: `${parentSlug}/private-key`,
},
{
name: "Engine Wallet",
href: `${parentSlug}/engine-wallet`,
},
],
};
})();
Expand Down Expand Up @@ -195,7 +199,7 @@ const transactions: SidebarLink = {
};

const pay: SidebarLink = {
name: "Pay",
name: "Payments",
isCollapsible: false,
links: [
{
Expand Down Expand Up @@ -285,6 +289,9 @@ export const sidebar: SideBar = {
},
],
},
{
separator: true,
},
{
name: "Core",
isCollapsible: false,
Expand All @@ -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: [
{
Expand All @@ -330,6 +360,9 @@ export const sidebar: SideBar = {
},
],
},
{
separator: true,
},
pay,
],
};
8 changes: 2 additions & 6 deletions apps/portal/src/app/dotnet/utils/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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`.
Expand Down
Original file line number Diff line number Diff line change
@@ -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}");
```

<Callout variant="warning" title="Important">
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.
</Callout>

<Details summary="Parameters">

### 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.

</Details>

<Details summary="Return Value">

### EngineWallet

Returns an instance of `EngineWallet`, ready to sign transactions and messages with the provided access token.

</Details>
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ The private key of the wallet, provided as a hexadecimal `string`. This key gran
</Details>

<Details summary="Return Value">
PrivateKeyWallet
### PrivateKeyWallet

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

Expand Down
40 changes: 27 additions & 13 deletions apps/portal/src/app/unity/v5/sidebar.tsx
Original file line number Diff line number Diff line change
@@ -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`;
Expand All @@ -23,6 +23,9 @@ export const sidebar: SideBar = {
isCollapsible: false,
icon: <CodeIcon />,
},
{
separator: true,
},
{
name: "Core",
isCollapsible: false,
Expand All @@ -38,7 +41,10 @@ export const sidebar: SideBar = {
],
},
{
name: "Wallets",
separator: true,
},
{
name: "Onboarding Users",
isCollapsible: false,
links: [
{
Expand Down Expand Up @@ -68,7 +74,10 @@ export const sidebar: SideBar = {
],
},
{
name: "Blockchain API",
separator: true,
},
{
name: "Onchain Interactions",
isCollapsible: false,
links: [
{
Expand All @@ -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: <ExternalLinkIcon />,
},
{
name: "Nebula AI",
href: "/dotnet/nebula/quickstart",
icon: <ExternalLinkIcon />,
},
{
name: "Payments",
href: "/dotnet/pay/quickstart",
icon: <ExternalLinkIcon />,
},
],
},

{ separator: true },
{
name: "Migrate from v4",
Expand Down
Loading