broadcastTx method

Future<TxResponse> broadcastTx(
  1. Tx tx, {
  2. TxConfig? config,
  3. BroadcastMode mode = BroadcastMode.BROADCAST_MODE_SYNC,
})

Broadcasts the given tx using the info contained inside the given wallet. Returns the hash of the transaction once it has been send, or throws an exception if an error is risen during the sending.

Implementation

Future<TxResponse> broadcastTx(
  Tx tx, {
  TxConfig? config,
  BroadcastMode mode = BroadcastMode.BROADCAST_MODE_SYNC,
}) async {
  config ??= DefaultTxConfig.create();
  final encoder = config.txEncoder();

  final request = BroadcastTxRequest()
    ..mode = mode
    ..txBytes = encoder(tx);

  final response = await _client.broadcastTx(request);
  return response.txResponse;
}