Skip to content

Commit

Permalink
Add .NET SDK docs
Browse files Browse the repository at this point in the history
  • Loading branch information
GhostWalker562 committed Sep 27, 2024
1 parent e5364e4 commit 56e5a42
Show file tree
Hide file tree
Showing 14 changed files with 877 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ Aptos currently provides four SDKs:
1. [Typescript](../sdks/ts-sdk.mdx)
2. [Python](../sdks/python-sdk.mdx)
3. [Rust](../sdks/rust-sdk.mdx)
4. [Unity](../sdks/unity-sdk.mdx)
4. [.NET](../sdks/dotnet-sdk.mdx)
5. [Go SDK](../sdks/go-sdk.mdx)
6. [Unity](../sdks/unity-sdk.mdx)


Almost all developers will benefit from exploring the CLI.
[Using the CLI](../cli.mdx) demonstrates how the CLI can be used to create
Expand Down
9 changes: 9 additions & 0 deletions apps/nextra/pages/en/build/sdks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ Use these Aptos software development kits (SDKs), in combination with the [Aptos
<Card.Title>Rust SDK</Card.Title>
<Card.Description>Aptos Rust SDK</Card.Description>
</div>
</Card>
<Card href="./sdks/dotnet-sdk" className="flex flex-row gap-4">
<Card.Image src="https://upload.wikimedia.org/wikipedia/commons/thumb/7/7d/Microsoft_.NET_logo.svg/800px-Microsoft_.NET_logo.svg.png" />
<div className="flex flex-col gap-2">
<Card.Title>C#/.NET SDK</Card.Title>
<Card.Description>
Aptos .NET SDK
</Card.Description>
</div>
</Card>
<Card href="./sdks/unity-sdk" className="flex flex-row gap-4">
<Card.Image src="https://cdn-icons-png.freepik.com/512/5969/5969346.png" />
Expand Down
3 changes: 3 additions & 0 deletions apps/nextra/pages/en/build/sdks/_meta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export default {
"rust-sdk": {
title: "Rust SDK",
},
"dotnet-sdk": {
title: ".NET SDK",
},
"unity-sdk": {
title: "Unity SDK",
},
Expand Down
86 changes: 86 additions & 0 deletions apps/nextra/pages/en/build/sdks/dotnet-sdk.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
title: ".NET SDK "
---

import { Card, Cards } from "@components/index";
import { Callout } from "nextra/components";

<Callout type="warning" emoji="">
This SDK is currently in beta. Please report any issues you encounter by
creating an issue in the
[aptos-labs/aptos-dotnet-sdk](https://github.com/aptos-labs/aptos-dotnet-sdk)
repository.
</Callout>

# Aptos .NET SDK (Beta)

Integrate Aptos web3 capabilities within your .NET applications. The goal of this SDK is to provide a set of tools
for developers to build multi-platform applications across compatible game engines and platforms.

**Supported Features**

- Binary Canonical Serialization (BCS) encoding and decoding
- Ed25519, SingleKey, MultiKey, and Keyless signer support
- Utilities for transaction building, signing, and submission
- Abstractions over the Aptos Fullnode and Indexer APIs
- Aptos Names (ANS) support for resolution and lookup

## Installation

The .NET SDK is available on [NuGet](https://www.nuget.org/packages/Aptos).

You can install the .NET SDK using the following command:

```bash
dotnet add package Aptos
```

## Gaming Integrations

Begin using the Aptos .NET SDK in your game engine of choice.

<Cards className="xl:grid-cols-2">
<Card href="./dotnet-sdk/godot-integration" className="flex flex-row gap-4">
<Card.Image src="https://upload.wikimedia.org/wikipedia/commons/thumb/6/6a/Godot_icon.svg/2048px-Godot_icon.svg.png" />
<div className="flex flex-col gap-2">
<Card.Title>Godot Integration</Card.Title>
<Card.Description>
Begin integrating into Godot projects.
</Card.Description>
</div>
</Card>
<Card href="./dotnet-sdk/unity-integration" className="flex flex-row gap-4">
<Card.Image src="https://cdn-icons-png.freepik.com/512/5969/5969346.png" />
<div className="flex flex-col gap-2">
<Card.Title>Unity Integration</Card.Title>
<Card.Description>
Begin integrating into Unity projects.
</Card.Description>
</div>
</Card>
</Cards>

### Compatibility

| .NET Version | Supported | Target Game Engines |
| ----------------- | --------- | ------------------- |
| .NET Standard 2.1 || Unity |
| .NET 6.0 || Godot |
| .NET 7.0 || Godot (Android) |
| .NET 8.0 || Godot (iOS) |

## Resources

<Cards className="xl:grid-cols-2">
<Card
href="./dotnet-sdk/getting-started"
className="col-span-2 flex flex-row gap-4"
>
<div className="flex flex-col gap-2">
<Card.Title>Getting Started</Card.Title>
<Card.Description>
Begin developing using the Aptos .NET SDK.
</Card.Description>
</div>
</Card>
</Cards>
17 changes: 17 additions & 0 deletions apps/nextra/pages/en/build/sdks/dotnet-sdk/_meta.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export default {
"getting-started": {
title: "Getting Started",
},
"unity-integration": {
title: "Unity Integration",
},
"godot-integration": {
title: "Godot Integration",
},
accounts: {
title: "Accounts",
},
transactions: {
title: "Transactions",
},
};
5 changes: 5 additions & 0 deletions apps/nextra/pages/en/build/sdks/dotnet-sdk/accounts/_meta.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
ed25519: {
title: "Ed25519 Accounts",
},
};
52 changes: 52 additions & 0 deletions apps/nextra/pages/en/build/sdks/dotnet-sdk/accounts/ed25519.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
title: "Ed25519 Accounts"
---

import { Steps, Callout } from "nextra/components";
import { Card, Cards } from "@components/index";

<Callout type="warning" emoji="">
This SDK is currently in beta. Please report any issues you encounter by
creating an issue in the
[aptos-labs/aptos-dotnet-sdk](https://github.com/aptos-labs/aptos-dotnet-sdk)
repository.
</Callout>

# Ed25519 Accounts

The Aptos .NET SDK provides a simple way to create and manage Ed25519 accounts. In this guide we
will provide snippets of creating or importing existing accounts.

## Creating Ed25519Accounts

Ed25519Accounts are created to sign transactions and interact with the blockchain.

### Using a Private Key

To generate an account from a private key, you will need to create the `Ed25519PrivateKey` object and pass into into the
`Ed25519Account` constructor. The private key can be given a `string` or `byte[]` representation.

```csharp
var privateKey = new Ed25519PrivateKey("0x1234...abcdef");
var account = new Ed25519Account(privateKey);
```

### Using a Mneomonic Phrase

To generate an account from a phrase, you can use `Ed25519Account.FromDerivationPath` and pass in the phrase and the derivation path.
The derivation path that is typically used throughout the Aptos ecosystem is `m/44'/637'/0'/0'/0'`.

```csharp
var account = Ed25519Account.FromDerivationPath(
"m/44'/637'/0'/0'/0'",
"apple banana cat dog elephant fox ..."
);
```

### Generating a Random Account

To create a random account, you can use the `Account.Generate()` method.

```csharp
var account = Account.Generate();
```
116 changes: 116 additions & 0 deletions apps/nextra/pages/en/build/sdks/dotnet-sdk/getting-started.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
---
title: "Quickstart"
---

import { Steps, Callout } from "nextra/components";
import { Card, Cards } from "@components/index";

<Callout type="warning" emoji="">
This SDK is currently in beta. Please report any issues you encounter by
creating an issue in the
[aptos-labs/aptos-dotnet-sdk](https://github.com/aptos-labs/aptos-dotnet-sdk)
repository.
</Callout>

# Getting Started

If you have not already installed the Aptos .NET SDK, follow one of the guides below to get started.

<Cards className="xl:grid-cols-2">
<Card href="./godot-integration" className="flex flex-row gap-4">
<Card.Image src="https://upload.wikimedia.org/wikipedia/commons/thumb/6/6a/Godot_icon.svg/2048px-Godot_icon.svg.png" />
<div className="flex flex-col gap-2">
<Card.Title>Godot Integration</Card.Title>
<Card.Description>
Integrate the Aptos .NET SDK with a Godot project.
</Card.Description>
</div>
</Card>
<Card href="./unity-integration" className="flex flex-row gap-4">
<Card.Image src="https://cdn-icons-png.freepik.com/512/5969/5969346.png" />
<div className="flex flex-col gap-2">
<Card.Title>Unity SDK</Card.Title>
<Card.Description>
Integrate the Aptos .NET SDK with a Unity project.
</Card.Description>
</div>
</Card>
</Cards>

<Steps>

### Set up your AptosClient

Set up your Aptos client by adding the `Aptos` namespace and instantiating an `AptosClient`. You can use a predefined
configuration from `Networks` or configuring your own.

```csharp filename="Program.cs" {1-1, 7-8}
using Aptos;

class Program
{
static void Main(string[] args)
{
var config = new AptosConfig(Aptos.Networks.Mainnet);
var client = new AptosClient(config);
}
}
```

### Query the Blockchain

Now that you have the client setup, you can query the blockchain!

```csharp filename="Program.cs" {10-11}
using Aptos;

class Program
{
static void Main(string[] args)
{
var config = new AptosConfig(Aptos.Networks.Mainnet);
var client = new AptosClient(config);

var ledgerInfo = client.Block.GetLedgerInfo();
Console.WriteLine(ledgerInfo.BlockHeight);
}
}
```

### Sign and Submit Transactions

To interact with the blockchain, you will need to create a signer and build a transaction.

```csharp filename="Program.cs" {10-11,13-21,23-24,26-27}
using Aptos;

class Program
{
static void Main(string[] args)
{
var config = new AptosConfig(Aptos.Networks.Mainnet);
var client = new AptosClient(config);

// 1. Create a signer
var signer = Account.Generate();

// 2. Build the transaction
var transaction = await client.Transaction.Build(
sender: account,
data: new GenerateEntryFunctionPayloadData(
function: "0x1::aptos_account::transfer_coins",
typeArguments: ["0x1::aptos_coin::AptosCoin"],
functionArguments: [account.Address, "100000"]
)
);

// 3. Sign and submit the transaction
var pendingTransaction = client.Transaction.SignAndSubmitTransaction(account, transaction);

// 4. (Optional) Wait for the transaction to be committed
var committedTransaction = await client.Transaction.WaitForTransaction(pendingTransaction);
}
}
```

</Steps>
Loading

0 comments on commit 56e5a42

Please sign in to comment.