Build Status

Libra Core

Libra Core is a Dart library client that can be used to interact with Libra nodes.

Thanks to JavaScript Libra Core from Perfect Makanju.

There is an example Flutter application built for Android, iOS coming soon.

Table of Content

Usage

There are two main interface classes:

  • LibraWallet
  • LibraClient

Creating an Account

Instantiate LibraWallet to create a libra account:

LibraWallet wallet = new LibraWallet();

Mnemonic is optional, a random mnemonic is generated and used without specifying one

const String mnemonic = 'danger gravity ... flip';
LibraWallet wallet = new LibraWallet(mnemonic: mnemonic);

A LibraWallet holds more than one LibraAccount objects, each account being a child of the wallet (start with index 0).

LibraAccount alice = wallet.newAccount();
LibraAccount bob = wallet.newAccount();

Generate addres from account:

String aliceAddress = alice.getAddress();

Minting Amount

Instantiate LibraClient and uses faucet service to mint, default config as Testnet:

LibraClient client = new LibraClient();
int amount = 1000000;
await client.mintWithFaucetService(aliceAddress, BigInt.from(amount), needWait: false);

Checking an address balance

Get state from alice which contains balance and other information such as sequenceNumber

LibraAccountState aliceState = await client.getAccountState(aliceAddress);
print('alice state: ${aliceState.balance}, ${aliceState.sequenceNumber}');

Transferring Libra Coins

Transfer from alice to bob, implemented with Libra Canonical Serialization:

LibraAccount bob = wallet.newAccount();
String bobAddress = bob.getAddress();
int amount = 1000000;
await client.transferCoins(alice, bobAddress, amount);

// Get bob state
LibraAccountState bobState = await client.getAccountState(bobAddress);
print('bob state: ${bobState.balance}, ${bobState.sequenceNumber}');

Query Transaction with Sequence Number

Query detail of the transaction sending from alice to bob, implemented with Libra Canonical Deserialization:

LibraSignedTransactionWithProof lastTransaction = await client.getAccountTransaction(aliceAddress, aliceState.sequenceNumber);
print('publicKey from alice: ${LibraHelpers.byteToHex(lastTransaction.signedTransaction.publicKey)}');

License

MIT

Libraries

access_path.pb
access_path.pbenum
access_path.pbjson
account_state_blob.pb
account_state_blob.pbenum
account_state_blob.pbjson
admission_control.pb
admission_control.pbenum
admission_control.pbgrpc
admission_control.pbjson
events.pb
events.pbenum
events.pbjson
flutter_libra_core
get_with_proof.pb
get_with_proof.pbenum
get_with_proof.pbjson
language_storage.pb
language_storage.pbenum
language_storage.pbjson
ledger_info.pb
ledger_info.pbenum
ledger_info.pbjson
mempool.pb
mempool.pbenum
mempool.pbgrpc
mempool.pbjson
mempool_status.pb
mempool_status.pbenum
mempool_status.pbjson
proof.pb
proof.pbenum
proof.pbjson
transaction.pb
transaction.pbenum
transaction.pbjson
transaction_info.pb
transaction_info.pbenum
transaction_info.pbjson
validator_change.pb
validator_change.pbenum
validator_change.pbjson
validator_public_keys.pb
validator_public_keys.pbenum
validator_public_keys.pbjson
validator_set.pb
validator_set.pbenum
validator_set.pbjson
vm_errors.pb
vm_errors.pbenum
vm_errors.pbjson
wrappers.pb
wrappers.pbenum
wrappers.pbjson