Skip to content

Commit cd8ffba

Browse files
authored
Update README.md
Signed-off-by: Firekeeper <[email protected]>
1 parent 6d7506a commit cd8ffba

File tree

1 file changed

+8
-303
lines changed

1 file changed

+8
-303
lines changed

README.md

Lines changed: 8 additions & 303 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
![net-banner](https://github.com/thirdweb-dev/thirdweb-dotnet/assets/43042585/6abcdae9-b49f-492a-98de-b01756e21798)
22

3+
[<img alt=".NET Documentation" src="https://img.shields.io/badge/.NET-Documentation-purple?logo=dotnet&style=for-the-badge" height="30">](https://portal.thirdweb.com/dotnet)
34
[<img alt="NuGet Version" src="https://img.shields.io/nuget/v/Thirdweb?logo=nuget&style=for-the-badge" height="30">](https://www.nuget.org/packages/Thirdweb)
45
[<img alt="NuGet Downloads" src="https://img.shields.io/nuget/dt/Thirdweb?logo=nuget&style=for-the-badge" height="30">](https://www.nuget.org/packages/Thirdweb)
56
[<img alt="Codecov" src="https://img.shields.io/codecov/c/github/thirdweb-dev/thirdweb-dotnet?logo=codecov&style=for-the-badge" height="30">](https://app.codecov.io/gh/thirdweb-dev/thirdweb-dotnet)
67

7-
88
## Overview
99

1010
The Thirdweb .NET SDK is a comprehensive library that allows developers to interact with the blockchain using the .NET framework. It simplifies the integration of Web3 functionality into your .NET applications with a robust set of methods and classes and a minimal amount of dependencies.
1111

12-
13-
1412
## Features
1513

1614
- **Connect to any EVM network:** Easily connect to Ethereum and other EVM-compatible networks.
@@ -23,7 +21,7 @@ The Thirdweb .NET SDK is a comprehensive library that allows developers to inter
2321
- **Transaction Builder:** Easily build and send transactions.
2422
- **Session Keys:** Advanced control for smart wallets to manage permissions and session durations.
2523
- **Thirdweb Pay:** Easily integrate fiat onramps and cross-chain crypto purchases.
26-
- **Unity Compatibility**: This SDK has been tested successfully in Unity 2022.3+ (Standalone, Mobile and WebGL).
24+
- **Unity Compatibility**: This SDK has been tested successfully in [Unity 2021.3+](https://portal.thirdweb.com/unity/v5) (Standalone, Mobile and WebGL).
2725
- **Godot Compatibility**: This SDK has been tested successfully in [Godot .NET](https://portal.thirdweb.com/dotnet/godot)
2826

2927
## Installation
@@ -36,307 +34,14 @@ Run the following command to install:
3634
dotnet add package Thirdweb
3735
```
3836

39-
## Usage
40-
41-
You can access the full documentation at https://portal.thirdweb.com/dotnet
42-
43-
Full API reference also available [here](https://thirdweb-dev.github.io/thirdweb-dotnet/).
44-
45-
### Getting Started
46-
47-
Initialize the Thirdweb client to connect to the blockchain.
48-
49-
For frontend applications:
50-
51-
```csharp
52-
var client = ThirdwebClient.Create(clientId: "myClientId", bundleId: "com.my.bundleid");
53-
```
54-
55-
For backend applications:
56-
57-
```csharp
58-
var secretKey = Environment.GetEnvironmentVariable("THIRDWEB_SECRET_KEY");
59-
var client = ThirdwebClient.Create(secretKey: secretKey);
60-
```
61-
62-
### Interacting with Smart Contracts
63-
64-
You can interact with smart contracts by creating a contract instance and calling read/write methods.
65-
66-
**Reading Data**
67-
68-
```csharp
69-
var contract = await ThirdwebContract.Create(client: client, address: "0x81ebd23aA79bCcF5AaFb9c9c5B0Db4223c39102e", chain: 421614);
70-
var readResult = await contract.Read<string>("name");
71-
Console.WriteLine($"Contract read result: {readResult}");
72-
```
73-
74-
**Writing Data**
75-
76-
```csharp
77-
var writeResult = await contract.Write(smartWallet, "mintTo", 0, await smartWallet.GetAddress(), 100);
78-
Console.WriteLine($"Contract write result: {writeResult}");
79-
```
80-
81-
**Using Extensions**
82-
83-
Thirdweb comes with very handy prebuilt extensions so you don't have to rely on dynamic parameters, available for any contract object.
37+
## Documentation
8438

85-
```csharp
86-
// ERC20 balanceOf
87-
var balance = await contract.ERC20_BalanceOf(ownerAddress: "0xOwner");
39+
[Documentation Portal](https://portal.thirdweb.com/dotnet)
8840

89-
// DropERC20 (Thirdweb Prebuilt Contract) claim
90-
var claimTx = await contract.DropERC20_Claim(wallet: privateKeyWallet, receiverAddress: "0xReceiver", amount: "1.5");
41+
[Full API Reference](https://thirdweb-dev.github.io/thirdweb-dotnet/)
9142

92-
// Miscellaneous
93-
var nativeContractBalance = await contract.GetBalance(); // Can also take in ERC20 address
94-
var nfts = await contract.ERC721_GetAllNFTs(); // Fetches all NFTs of a contract
95-
var nftImageBytes = await nfts[0].GetNFTImageBytes(client); // NFT type extension to get image bytes
96-
```
97-
98-
Extensions exist for various common standards, thirdweb-specific prebuilt contracts and much more!
99-
100-
### Wallet Interactions
101-
102-
#### In-App Wallets
103-
104-
In-app wallets facilitate user authentication and transactions with support for email, phone, and OAuth logins.
105-
106-
**Email Login**
107-
108-
```csharp
109-
var inAppWallet = await InAppWallet.Create(client: client, email: "[email protected]");
110-
111-
if (!await inAppWallet.IsConnected()) {
112-
await inAppWallet.SendOTP();
113-
Console.WriteLine("Please submit the OTP.");
114-
var otp = Console.ReadLine();
115-
(var inAppWalletAddress, var canRetry) = await inAppWallet.SubmitOTP(otp);
116-
if (inAppWalletAddress == null && canRetry) {
117-
Console.WriteLine("Please submit the OTP again.");
118-
otp = Console.ReadLine();
119-
(inAppWalletAddress, _) = await inAppWallet.SubmitOTP(otp);
120-
}
121-
if (inAppWalletAddress == null) {
122-
Console.WriteLine("OTP login failed. Please try again.");
123-
return;
124-
}
125-
}
126-
127-
Console.WriteLine($"InAppWallet: {await inAppWallet.GetAddress()}");
128-
```
129-
130-
**OAuth Login**
131-
132-
```csharp
133-
var inAppWallet = await InAppWallet.Create(client, oauthProvider: OAuthProvider.Google);
134-
135-
// Windows console app example
136-
var address = await inAppWallet.LoginWithOauth(
137-
isMobile: false,
138-
browserOpenAction: (url) =>
139-
{
140-
var psi = new ProcessStartInfo { FileName = url, UseShellExecute = true };
141-
_ = Process.Start(psi);
142-
},
143-
);
144-
145-
// Godot standalone example
146-
var address = await ThirdwebManager.Instance.InAppWallet.LoginWithOauth(
147-
isMobile: OS.GetName() == "Android" || OS.GetName() == "iOS",
148-
browserOpenAction: (url) => OS.ShellOpen(url),
149-
mobileRedirectScheme: "thirdweb://"
150-
);
151-
```
152-
153-
#### Smart Wallets
154-
155-
Smart wallets offer advanced functionalities such as gasless transactions and session keys.
156-
157-
**Creating a Smart Wallet**
158-
159-
```csharp
160-
var smartWallet = await SmartWallet.Create(personalWallet: inAppWallet, gasless: true, chainId: 421614);
161-
162-
Console.WriteLine($"Smart Wallet: {await smartWallet.GetAddress()}");
163-
```
164-
165-
**Gasless Transactions**
166-
167-
```csharp
168-
var writeResult = await contract.Write(smartWallet, "mintTo", 0, await smartWallet.GetAddress(), 100);
169-
Console.WriteLine($"Gasless transaction result: {writeResult}");
170-
```
43+
## Need Help?
17144

172-
**Session Key Creation**
173-
174-
Session keys provide temporary keys for smart wallets with specific permissions and durations. This is useful for granting limited access to a wallet.
175-
176-
```csharp
177-
var sessionKey = await smartWallet.CreateSessionKey(
178-
signerAddress: await privateKeyWallet.GetAddress(),
179-
approvedTargets: new List<string>() { Constants.ADDRESS_ZERO },
180-
nativeTokenLimitPerTransactionInWei: "0",
181-
permissionStartTimestamp: "0",
182-
permissionEndTimestamp: (Utils.GetUnixTimeStampNow() + 86400).ToString(),
183-
reqValidityStartTimestamp: "0",
184-
reqValidityEndTimestamp: Utils.GetUnixTimeStampIn10Years().ToString()
185-
);
186-
```
187-
188-
You may then connect to a specific smart wallet address by passing an account override.
189-
190-
```csharp
191-
var smartWallet = await SmartWallet.Create(...same parameters with new signer, accountAddressOverride: "0xInitialSmartWalletAddress");
192-
```
193-
194-
#### Using Private Key Wallets
195-
196-
Private key wallets allow you to interact with the blockchain using a private key. This is useful for server-side applications.
197-
198-
```csharp
199-
var privateKey = Environment.GetEnvironmentVariable("PRIVATE_KEY");
200-
var privateKeyWallet = await PrivateKeyWallet.Create(client: client, privateKeyHex: privateKey);
201-
Console.WriteLine($"PrivateKey Wallet: {await privateKeyWallet.GetAddress()}");
202-
203-
// or generate a private key wallet
204-
var generatedPrivateKeyWallet = await PrivateKeyWallet.Generate(client);
205-
```
206-
207-
### Advanced Features
208-
209-
**RPC Direct Access**
210-
211-
Directly interact with the blockchain using the RPC instance. This allows for low-level access to blockchain data and functions.
212-
213-
```csharp
214-
var rpc = ThirdwebRPC.GetRpcInstance(client, 421614);
215-
var blockNumber = await rpc.SendRequestAsync<string>("eth_blockNumber");
216-
Console.WriteLine($"Block number: {blockNumber}");
217-
```
218-
219-
**ZkSync Native Account Abstraction**
220-
221-
ZkSync 0x71 (113) type transactions are supported through the Transaction Builder (DIY) or Smart Wallets (Managed).
222-
223-
**DIY Approach**
224-
225-
```csharp
226-
var tx = await ThirdwebTransaction.Create(
227-
wallet: privateKeyWallet,
228-
txInput: new ThirdwebTransactionInput()
229-
{
230-
From = await privateKeyWallet.GetAddress(),
231-
To = await privateKeyWallet.GetAddress(),
232-
Value = new HexBigInteger(BigInteger.Zero),
233-
},
234-
chainId: 300
235-
);
236-
tx.SetZkSyncOptions(
237-
new ZkSyncOptions(
238-
paymaster: "0xMyGaslessPaymaster",
239-
paymasterInput: "0x8c5a344500000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000"
240-
)
241-
);
242-
var txHash = await ThirdwebTransaction.Send(transaction: tx);
243-
Console.WriteLine($"Transaction hash: {txHash}");
244-
```
245-
246-
**Managed Approach**
247-
248-
With ZkSync, you don't need to pass an account factory address, and the rest works the same.
249-
250-
```csharp
251-
var zkSyncWallet = await SmartWallet.Create(personalWallet: inAppWallet, gasless: true, chainId: 300);
252-
253-
Console.WriteLine($"ZkSync Smart Wallet: {await zkSyncWallet.GetAddress()}");
254-
255-
var zkSyncWriteResult = await contract.Write(zkSyncWallet, "mintTo", 0, await zkSyncWallet.GetAddress(), 100);
256-
Console.WriteLine($"ZkSync gasless transaction result: {zkSyncWriteResult}");
257-
```
258-
259-
**Storage Solutions**
260-
261-
Download and upload files using IPFS. This is useful for decentralized storage solutions.
262-
263-
```csharp
264-
var downloadResult = await ThirdwebStorage.Download<string>(client: client, uri: "ipfs://exampleUri");
265-
Console.WriteLine($"Download result: {downloadResult}");
266-
267-
var uploadResult = await ThirdwebStorage.Upload(client: client, path: "path/to/file");
268-
Console.WriteLine($"Upload result preview: {uploadResult.PreviewUrl}");
269-
```
270-
271-
### Thirdweb Pay
272-
273-
Easily integrate fiat onramps and cross-chain crypto purchases.
274-
275-
**Buy With Crypto**
276-
277-
```csharp
278-
// Swap Polygon MATIC to Base ETH
279-
var swapQuoteParams = new BuyWithCryptoQuoteParams(
280-
fromAddress: walletAddress,
281-
fromChainId: 137,
282-
fromTokenAddress: Thirdweb.Constants.NATIVE_TOKEN_ADDRESS,
283-
toTokenAddress: Thirdweb.Constants.NATIVE_TOKEN_ADDRESS,
284-
toChainId: 8453,
285-
toAmount: "0.1"
286-
);
287-
var swapQuote = await ThirdwebPay.GetBuyWithCryptoQuote(client, swapQuoteParams);
288-
Console.WriteLine($"Swap quote: {JsonConvert.SerializeObject(swapQuote, Formatting.Indented)}");
289-
290-
// Initiate swap
291-
var txHash = await ThirdwebPay.BuyWithCrypto(wallet: privateKeyWallet, buyWithCryptoQuote: swapQuote);
292-
Console.WriteLine($"Swap transaction hash: {txHash}");
293-
294-
// Poll for status
295-
var currentSwapStatus = SwapStatus.NONE;
296-
while (currentSwapStatus is not SwapStatus.COMPLETED and not SwapStatus.FAILED)
297-
{
298-
var swapStatus = await ThirdwebPay.GetBuyWithCryptoStatus(client, txHash);
299-
currentSwapStatus = Enum.Parse<SwapStatus>(swapStatus.Status);
300-
Console.WriteLine($"Swap status: {JsonConvert.SerializeObject(swapStatus, Formatting.Indented)}");
301-
await Task.Delay(5000);
302-
}
303-
```
304-
305-
**Buy With Fiat**
306-
307-
```csharp
308-
// Find out more about supported FIAT currencies
309-
var supportedCurrencies = await ThirdwebPay.GetBuyWithFiatCurrencies(client);
310-
Console.WriteLine($"Supported currencies: {JsonConvert.SerializeObject(supportedCurrencies, Formatting.Indented)}");
311-
312-
// Get a Buy with Fiat quote
313-
var fiatQuoteParams = new BuyWithFiatQuoteParams(
314-
fromCurrencySymbol: "USD",
315-
toAddress: walletAddress,
316-
toChainId: "137",
317-
toTokenAddress: Thirdweb.Constants.NATIVE_TOKEN_ADDRESS,
318-
toAmount: "20"
319-
);
320-
var fiatOnrampQuote = await ThirdwebPay.GetBuyWithFiatQuote(client, fiatQuoteParams);
321-
Console.WriteLine($"Fiat onramp quote: {JsonConvert.SerializeObject(fiatOnrampQuote, Formatting.Indented)}");
322-
323-
// Get a Buy with Fiat link
324-
var onRampLink = ThirdwebPay.BuyWithFiat(fiatOnrampQuote);
325-
Console.WriteLine($"Fiat onramp link: {onRampLink}");
326-
327-
// Open onramp link to start the process (use your framework's version of this)
328-
var psi = new ProcessStartInfo { FileName = onRampLink, UseShellExecute = true };
329-
_ = Process.Start(psi);
330-
331-
// Poll for status
332-
var currentOnRampStatus = OnRampStatus.NONE;
333-
while (currentOnRampStatus is not OnRampStatus.ON_RAMP_TRANSFER_COMPLETED and not OnRampStatus.ON_RAMP_TRANSFER_FAILED)
334-
{
335-
var onRampStatus = await ThirdwebPay.GetBuyWithFiatStatus(client, fiatOnrampQuote.IntentId);
336-
currentOnRampStatus = Enum.Parse<OnRampStatus>(onRampStatus.Status);
337-
Console.WriteLine($"Fiat onramp status: {JsonConvert.SerializeObject(onRampStatus, Formatting.Indented)}");
338-
await Task.Delay(5000);
339-
}
340-
```
45+
For any questions or support, visit our [Support Portal](https://thirdweb.com/support).
34146

342-
For more information, please refer to the [official documentation](https://portal.thirdweb.com/dotnet).
47+
Thank you for trying out the Thirdweb Unity SDK!

0 commit comments

Comments
 (0)