Skip to content
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

Thirdweb.Pay NSwag // Basic API #1

Closed
wants to merge 1 commit into from
Closed
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
31 changes: 16 additions & 15 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="dotenv.net" Version="3.1.3" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.7.1" />
<PackageVersion Include="xunit" Version="2.4.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.4.5" />
<PackageVersion Include="coverlet.collector" Version="3.2.0" />
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
<PackageVersion Include="Nethereum.ABI" Version="4.19.0" />
<PackageVersion Include="Nethereum.Hex" Version="4.19.0" />
<PackageVersion Include="Nethereum.Contracts" Version="4.19.0" />
</ItemGroup>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="dotenv.net" Version="3.1.3" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.7.1" />
<PackageVersion Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageVersion Include="xunit" Version="2.4.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.4.5" />
<PackageVersion Include="coverlet.collector" Version="3.2.0" />
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
<PackageVersion Include="Nethereum.ABI" Version="4.19.0" />
<PackageVersion Include="Nethereum.Hex" Version="4.19.0" />
<PackageVersion Include="Nethereum.Contracts" Version="4.19.0" />
</ItemGroup>
</Project>
40 changes: 28 additions & 12 deletions Thirdweb.Console/Program.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,40 @@
using dotenv.net;
using Newtonsoft.Json;
using Thirdweb;
using Thirdweb.Pay;

DotEnv.Load();

var secretKey = Environment.GetEnvironmentVariable("THIRDWEB_SECRET_KEY");
// var secretKey = Environment.GetEnvironmentVariable("THIRDWEB_SECRET_KEY");

var clientOptions = new ThirdwebClientOptions(secretKey: secretKey, fetchTimeoutOptions: new TimeoutOptions(storage: 30000, rpc: 10000));
var client = new ThirdwebClient(clientOptions);
// var clientOptions = new ThirdwebClientOptions(secretKey: secretKey, fetchTimeoutOptions: new TimeoutOptions(storage: 30000, rpc: 10000));
// var client = new ThirdwebClient(clientOptions);

Console.WriteLine($"Initialized ThirdwebClient: {JsonConvert.SerializeObject(clientOptions, Formatting.Indented)}");
// Console.WriteLine($"Initialized ThirdwebClient: {JsonConvert.SerializeObject(clientOptions, Formatting.Indented)}");

var rpc = ThirdwebRPC.GetRpcInstance(client, 1);
var blockNumber = await rpc.SendRequestAsync<string>("eth_blockNumber");
Console.WriteLine($"Block number: {blockNumber}");
// var rpc = ThirdwebRPC.GetRpcInstance(client, 1);
// var blockNumber = await rpc.SendRequestAsync<string>("eth_blockNumber");
// Console.WriteLine($"Block number: {blockNumber}");

var contractOptions = new ThirdwebContractOptions(client: client, address: "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D", chain: 1, abi: "function name() view returns (string)");
var contract = new ThirdwebContract(contractOptions);
var readResult = await ThirdwebContract.ReadContract<string>(contract, "name");
// var contractOptions = new ThirdwebContractOptions(client: client, address: "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D", chain: 1, abi: "function name() view returns (string)");
// var contract = new ThirdwebContract(contractOptions);
// var readResult = await ThirdwebContract.ReadContract<string>(contract, "name");

Console.WriteLine($"Contract read result: {readResult}");
// Console.WriteLine($"Contract read result: {readResult}");

Console.ReadLine();
// Console.ReadLine();

// Thirdweb Pay Test

var secretKey = Environment.GetEnvironmentVariable("THIRDWEB_PAY_SECRET_KEY");

var payClient = new ThirdwebPay(new ThirdwebPayOptions(secretKey: secretKey));

var quote = await payClient.GetQuoteAsync(
fromAddress: "0xDaaBDaaC8073A7dAbdC96F6909E8476ab4001B34",
fromChainId: 137,
fromTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
toTokenAddress: "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",
toAmount: "1"
);
Console.WriteLine($"Swap quote: {JsonConvert.SerializeObject(quote)}");
1 change: 1 addition & 0 deletions Thirdweb.Console/Thirdweb.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<ItemGroup>
<ProjectReference Include="..\Thirdweb\Thirdweb.csproj" />
<ProjectReference Include="..\Thirdweb.Pay\Thirdweb.Pay.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 5 additions & 0 deletions Thirdweb.Pay/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Thirdweb Pay .NET SDK

## Overview

The Thirdweb Pay .NET SDK is a powerful library that allows developers to swap, bridge and onramp using various blockchains and payment providers.
38 changes: 38 additions & 0 deletions Thirdweb.Pay/Thirdweb.Pay.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>$(DefaultTargetFrameworks)</TargetFrameworks>
<PackageVersion>$(DefaultVersion)</PackageVersion>
<AssemblyVersion>$(DefaultVersion)</AssemblyVersion>
<FileVersion>$(DefaultVersion)</FileVersion>
<PackageId>Thirdweb.Pay</PackageId>
<Title>Thirdweb Pay</Title>
<Authors>0xfirekeeper</Authors>
<Description>Best in class Web3 .NET Swap/OnRamp SDK, powered by thirdweb.</Description>
<Copyright>Copyright (c) thirdweb 2024</Copyright>
<PackageProjectUrl>https://thirdweb.com/</PackageProjectUrl>
<PackageIcon>icon.png</PackageIcon>
<RepositoryUrl>https://github.com/thirdweb-dev/thirdweb-dotnet</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>thirdweb wallet contracts client web3 ethereum blockchain game unity godot</PackageTags>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
</PropertyGroup>

<PropertyGroup>
<PackageReadmeFile>README.md</PackageReadmeFile>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" />
<PackageReference Include="System.ComponentModel.Annotations" />
</ItemGroup>

<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="\" />
<None Include="..\resources\icon.png" Pack="true" PackagePath="\" />
</ItemGroup>

</Project>
37 changes: 37 additions & 0 deletions Thirdweb.Pay/ThirdwebPay.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
namespace Thirdweb.Pay
{
public class ThirdwebPay
{
public ThirdwebPayOptions Options { get; private set; }

private ThirdwebPayClient _client;

public ThirdwebPay(ThirdwebPayOptions options)
{
Options = options;

HttpClient payHttpClient = new HttpClient() { DefaultRequestHeaders = { { "x-secret-key", Options.SecretKey } } };
_client = new ThirdwebPayClient("https://pay.thirdweb.com/", payHttpClient);
}

public async Task<Result5> GetQuoteAsync(string fromAddress, int fromChainId, string fromTokenAddress, string toTokenAddress, string toAmount)
{
var quote = await _client.GetSwapQuoteAsync(fromAddress: fromAddress, fromChainId: fromChainId, fromTokenAddress: fromTokenAddress, toTokenAddress: toTokenAddress, toAmount: toAmount);
// TODO: Check errors
// TODO: Parse into human readable type
return quote.Result;
}

// TODO: Swap

public async Task<Result6> GetSwapStatus(string transactionHash)
{
var swap = await _client.GetSwapStatusAsync(transactionHash);
// TODO: Check errors
// TODO: Parse into human readable type
return swap.Result;
}

// TODO: History
}
}
Loading
Loading