Terra.Microsoft.Client 1.0.7

dotnet add package Terra.Microsoft.Client --version 1.0.7
                    
NuGet\Install-Package Terra.Microsoft.Client -Version 1.0.7
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Terra.Microsoft.Client" Version="1.0.7" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Terra.Microsoft.Client" Version="1.0.7" />
                    
Directory.Packages.props
<PackageReference Include="Terra.Microsoft.Client" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Terra.Microsoft.Client --version 1.0.7
                    
#r "nuget: Terra.Microsoft.Client, 1.0.7"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Terra.Microsoft.Client@1.0.7
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Terra.Microsoft.Client&version=1.0.7
                    
Install as a Cake Addin
#tool nuget:?package=Terra.Microsoft.Client&version=1.0.7
                    
Install as a Cake Tool

Terra.Microsoft.Client is a C# SDK for writing applications that interact with the Terra blockchain from either the Web or Mobile, or .net environments and provides simple abstractions over core data structures, serialization, key management, and API request generation.

Features

  • Written in C#, with type definitions
  • Versatile support for key management solutions
  • Works with Xamarin, MAUI, in the browser, and Mobile
  • Exposes the Terra API through LCDClient
  • Parses responses into native C# types

We highly suggest using Terra.Microsoft.Client in a code editor that has support for type declarations, so you can take advantage of the helpful type hints that are included with the package.

Installation & Configuration

Grab the latest version off Nuget

dotnet add package Terra.Microsoft.Client

Please make sure to add the following nuget Packages into your .csproj file

<ItemGroup>
      <PackageReference Include="Cryptography.ECDSA.Secp256k1" Version="1.1.3" />
      <PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
      <PackageReference Include="Microsoft.Extensions.Http.Polly" Version="6.0.9" />
      <PackageReference Include="modernhttpclient-updated" Version="3.4.3" />
      <PackageReference Include="NBitcoin" Version="7.0.23" />
      <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
      <PackageReference Include="Ninject" Version="3.3.6" />
      <PackageReference Include="Polly" Version="7.2.3" />
      <PackageReference Include="Polly.Extensions.Http" Version="3.0.0" />
      <PackageReference Include="RandomStringCreator" Version="2.0.0" />
      <PackageReference Include="System.Security.Cryptography.Algorithms" Version="4.3.1" />
      <PackageReference Include="protobuf-net" Version="3.1.22" />
      <PackageReference Include="Protobuf.Grpc" Version="1.0.170" />
      <PackageReference Include="Terra.Microsoft.Extensions" Version="1.0.1" />
      <PackageReference Include="Terra.Microsoft.ProtoBufs" Version="1.0.1" />
      <PackageReference Include="Terra.Microsoft.Rest" Version="1.0.0" />
</ItemGroup>

Inside your Startup Class (Where you initialize your application), please call the following method, and configure your environment

// Here we're targeting the Classic Blockchain
TerraStartup.InitializeKernel(TerraEnvironment.Classic);

That's it! Now you're ready to start communicating with the blockchain!

Usage

Terra.Microsoft.Client can be used for Mobile & Web Developers. Supports all Microsoft Technologies from Xamarin, MAUI, ASP & Unity.

Getting Blockchain data

❗ Terra.Microsoft.Client can connect to both the terra-classic (LUNC/USTC) and LUNA2 networks. If you want to communicate with the classic chain, you have to set your Enviornment on TerraStartup.InitializeKernel to TerraEnvironment.Classic.

Below we're going to pull balance information on a sample wallet.

async void FetchBalanceInformation() {
    //fetch the LCDClient from the Kernel
    var lcd = TerraStartup.GetLCDClient();
    
    // get the current balance of "terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v"
    var balance = await lcd.bank.GetBalance("terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v");
    Console.WriteLine(balance);
}

Broadcasting transactions

First, get some testnet tokens for "terra17lmam6zguazs5q5u6z5mmx76uj63gldnse2pdp". Here we are going to send some tokens to a recipient address.

async void BroadcastTransaction() {
    // Create a key out of a mnemonic
    var mnemonic = new MnemonicKey("notice oak worry limit wrap speak medal online prefer cluster roof addict wrist behave treat actual wasp year salad speed social layer crew genius");

    // Define the recipient address
    var rAddr = "terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v";

    // Define your wallet -- The account that will handle the transactions
    var wallet = TerraStartup.GetLCDClient().CreateWallet("terra17lmam6zguazs5q5u6z5mmx76uj63gldnse2pdp", mnemonic);

    // Define your message to broadcast
    var send = new MsgSend(
       wallet.accAddress,
       rAddr,
       new List<Core.Coin>() { new Core.Coin(CoinDenoms.ULUNA, 20) });

    var msgs = new object[] { send };

    // Calculate the estimated Gas required for the transaction to succeed (it auto accounts for the new burn tax)
    var gas = await wallet.EstimateGasForTx(100000, msgs);
    
    // Calculate the fees required to handle the transaction
    var feeEstimate = await wallet.EstimateFeeForTx(100000, new CreateTxOptions()
    {
       gas = gas,
       feeDenom = CoinDenoms.ULUNA,
       gasAdjustment = 3,
    });
 
    // Broadcast the transaction 
    var broadcast = await wallet.broadcastTx.Broadcast(await wallet.CreateTxAndSignTx(feeEstimate, msgs));
    System.Diagnostics.Debug.WriteLine("Uploaded Tx Hash" + broadcast.Txhash);
}

Require Payment Integration for LUNC/USTC?

If you need to integrate with an external payment system or gateway like Apple/Google in app purchases, please make sure to install the following library in your project.

If you require a lightweight on-chain payments library, please make sure to install the following library in your project.

Terra.Microsoft.Client For Unity Developers

If you are using Terra.Microsoft.Client for Unity, please make sure to install the following asset in your project, and follow the installation instructions above

License

This software is licensed under the MIT license. See LICENSE for full disclosure.

© 2022 TerraMystics.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.7 447 2/24/2023
1.0.6 371 2/17/2023
1.0.5 388 2/17/2023
1.0.4 351 2/17/2023
1.0.3 374 2/3/2023
1.0.2 423 2/3/2023
1.0.1 490 12/28/2022
1.0.0 487 12/28/2022

Package Update