sendTransaction method

Future sendTransaction(
  1. Transaction transaction
)

Asks connected wallet to sign and send the transaction.

Implementation

Future<dynamic> sendTransaction(Transaction transaction) async {
  if (!connected) {
    throw WalletNotConnectedError(null);
  }

  Json options = {
    'required_messages_number': transaction.messages.length
  };
  _checkSendTransactionSupport(wallet!.device!.features, options);

  Json request = {
    'valid_until': transaction.validUntil,
    'from': transaction.from ?? wallet!.account!.address,
    'network': transaction.network?.value ?? wallet!.account!.chain.value,
    'messages': transaction.messages.map((e) => e.toMap()).toList(),
  };

  Json response = await provider!
      .sendRequest(SendTransactionParser().convertToRpcRequest(request));

  if (SendTransactionParser().isError(response)) {
    return SendTransactionParser().parseAndThrowError(response);
  }

  return SendTransactionParser().convertFromRpcResponse(response);
}