vite 0.3.1 copy "vite: ^0.3.1" to clipboard
vite: ^0.3.1 copied to clipboard

A dart library for the Vite blockchain. Send transactions and interact with smart contracts!

example/example.dart

import 'package:vite/vite.dart';

Future<void> main() async {
  final client = RpcClient.ws('wss://node.vite.net/gvite/ws');

  // create snapshot block subscription
  final blockSubscriction =
      await client.subscribe.createSnapshotBlockSubscription((response) {
    final messages = response.typedMessages<RpcSnapshotBlockMessage>();
    for (final message in messages) {
      if (message.removed) {
        print(
            'Removed snapshot block ${message.hash} - height ${message.height}');
        return;
      }
      print('New snapshot block ${message.hash} - height ${message.height}');
    }
  });

  // create account block subscription
  final accountSubscription =
      await client.subscribe.createAccountBlockSubscription((response) async {
    final messages = response.typedMessages<RpcAccountBlockMessage>();
    for (final message in messages) {
      if (message.removed) {
        print('Removed account block ${message.hash}');
        return;
      }
      // fetch new account block
      final accountBlock =
          await client.ledger.getAccountBlockByHash(message.hash);
      print('New account block for ${accountBlock.address}');
    }
  });

  // wait for new snapshot and account blocks
  await Future.delayed(const Duration(seconds: 60));

  await client.unsubscribe(accountSubscription);
  await client.unsubscribe(blockSubscriction);

  // give client time to finish any pending account block requests
  await Future.delayed(const Duration(seconds: 2));
  await client.close();

  print('Done');
}
0
likes
120
points
77
downloads

Publisher

verified publisherviterium.io

Weekly Downloads

A dart library for the Vite blockchain. Send transactions and interact with smart contracts!

Homepage
Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

bip39, decimal, freezed_annotation, hex, http, json_annotation, json_converter, json_rpc_2, pointycastle, stream_channel, string_validator, typed_data, web_socket_channel

More

Packages that depend on vite