terra_dart 1.0.5 copy "terra_dart: ^1.0.5" to clipboard
terra_dart: ^1.0.5 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 · Pub 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 TerraDart 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 pub.dev

terra_dart: latest

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 #

TerraDart can be used for Mobile & Web Developers. Supports all Flutter & Dart Environments.

Getting Blockchain data #

❗ TerraDart 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.

void fetchBalanceInformation() async {
    
    //fetch the LCDClient from the Kernel
    var lcd = TerraStartup.getLCDClient();
    
    // get the current balance of "terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v"
    var balance = await lcd.bank.getBalance("terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v");
    print(balance);
}

Broadcasting transactions #

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

void broadcastTransaction() async {
    
    //fetch the LCDClient from the Kernel
    var lcd = TerraStartup.getLCDClient();
    
    // create a key out of a mnemonic
    var mk = 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");

    // create a simple message that moves coin balances
    var send = 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([send])

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

License #

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

© 2022 TerraRebels.

0
likes
45
pub points
36%
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

Documentation

Documentation
API reference

Funding

Consider supporting this project:

www.terrarebels.net

License

MIT (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