terra_dart 1.0.0 copy "terra_dart: ^1.0.0" to clipboard
terra_dart: ^1.0.0 copied to clipboard

TerraDart is the Dart Implementation of Terra.js, the TypeScript Library for developing on Terra Luna. Library For Flutter & Dart Applications


The Official Dart SDK for the Terra Ecosystem (LUNC/USTC/LUNA2)


GitHub GitHub GitHub

Explore the Docs »

Example App · API Reference · Nuget Package · GitHub

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

Features #

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

We highly suggest using TerraSharp 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 TerraSharp

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

<ItemGroup>
	<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
	<PackageReference Include="Crypto.RIPEMD" Version="1.0.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="Nano.Bech32" Version="1.1.0" />
	<PackageReference Include="Nethereum.HdWallet" Version="4.11.0" />
	<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="TerraNetExtensions" Version="1.0.2" />
	<PackageReference Include="TerraProtoBufs" Version="1.0.0" />
	<PackageReference Include="Websocket.Client" Version="4.4.43" />
	<PackageReference Include="protobuf-net" Version="3.1.22" />
	<PackageReference Include="Protobuf.Grpc" Version="1.0.170" />
</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-Sharp can be used for Mobile & Web Developers. Supports all Microsoft Technologies from Xamarin, MAUI, ASP & Unity.

Getting Blockchain data #

❗ TerraSharp 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.GetService<LCDClient>();
    
    // get the current balance of "terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v"
    var balance = await lcd.bank.GetBalance("terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v");
    Console.WriteLine(balance);
}

Broadcasting transactions #

First, get some testnet tokens for "terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v", or use LocalTerra.


async void BroadcastTransaction() {
    
    //fetch the LCDClient from the Kernel
    var lcd = TerraStartup.GetLCDClient();
    
    // create a key out of a mnemonic
    var mk = new MnemonicKey();

    // create a simple message that moves coin balances
    var send = new MsgSend(
      "terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v",
      "terra17lmam6zguazs5q5u6z5mmx76uj63gldnse2pdp",
      new List<Core.Coin>() { new Core.Coin(CoinDenoms.ULUNA, 20) }
    );

    // Prepare & Configure your wallet
    var wallet = lcd.CreateWallet(PreconfiguredWallets.TEST_NET_WALLET, mk);
     
    // Prepare Transaction for Upload
    var tx = await wallet.CreateTxAndSignTx(new object[] { send })

    // Broadcast the transaction
    var broadcast = await wallet.broadcastTx.Broadcast(tx);     
    Console.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.

TerraSharp For Unity Developers #

If you are using TerraSharp 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 TerraRebels.

0
likes
0
pub points
30%
popularity

Publisher

unverified uploader

TerraDart is the Dart Implementation of Terra.js, the TypeScript Library for developing on Terra Luna. Library For Flutter & Dart Applications

Repository (GitHub)
View/report issues

Funding

Consider supporting this project:

www.terrarebels.net

License

unknown (LICENSE)

Dependencies

bech32, bip32, bip39, buffer, crypto, decimal, grpc, hash, http, injector, json_annotation, path, pointycastle, proto_annotations, protobuf, protobuf_google, random_string_generator, secp256k1, string_extensions, validated

More

Packages that depend on terra_dart