simulateTransaction method

Future<Response<BuiltList<UserTransaction>>> simulateTransaction({
  1. required SubmitTransactionRequest submitTransactionRequest,
  2. bool? estimateMaxGasAmount,
  3. bool? estimateGasUnitPrice,
  4. bool? estimatePrioritizedGasUnitPrice,
  5. CancelToken? cancelToken,
  6. Map<String, dynamic>? headers,
  7. Map<String, dynamic>? extra,
  8. ValidateStatus? validateStatus,
  9. ProgressCallback? onSendProgress,
  10. ProgressCallback? onReceiveProgress,
})

Simulate transaction The output of the transaction will have the exact transaction outputs and events that running an actual signed transaction would have. However, it will not have the associated state hashes, as they are not updated in storage. This can be used to estimate the maximum gas units for a submitted transaction. To use this, you must: - Create a SignedTransaction with a zero-padded signature. - Submit a SubmitTransactionRequest containing a UserTransactionRequest containing that signature. To use this endpoint with BCS, you must submit a SignedTransaction encoded as BCS. See SignedTransaction in types/src/transaction/mod.rs.

Parameters:

  • submitTransactionRequest
  • estimateMaxGasAmount - If set to true, the max gas value in the transaction will be ignored and the maximum possible gas will be used
  • estimateGasUnitPrice - If set to true, the gas unit price in the transaction will be ignored and the estimated value will be used
  • estimatePrioritizedGasUnitPrice - If set to true, the transaction will use a higher price than the original estimate.
  • cancelToken - A CancelToken that can be used to cancel the operation
  • headers - Can be used to add additional headers to the request
  • extras - Can be used to add flags to the request
  • validateStatus - A ValidateStatus callback that can be used to determine request success based on the HTTP status of the response
  • onSendProgress - A ProgressCallback that can be used to get the send progress
  • onReceiveProgress - A ProgressCallback that can be used to get the receive progress

Returns a Future containing a Response with a BuiltList<UserTransaction> as data Throws DioError if API call or serialization fails

Implementation

Future<Response<BuiltList<UserTransaction>>> simulateTransaction({
  required SubmitTransactionRequest submitTransactionRequest,
  bool? estimateMaxGasAmount,
  bool? estimateGasUnitPrice,
  bool? estimatePrioritizedGasUnitPrice,
  CancelToken? cancelToken,
  Map<String, dynamic>? headers,
  Map<String, dynamic>? extra,
  ValidateStatus? validateStatus,
  ProgressCallback? onSendProgress,
  ProgressCallback? onReceiveProgress,
}) async {
  final _path = r'/transactions/simulate';
  final _options = Options(
    method: r'POST',
    headers: <String, dynamic>{
      ...?headers,
    },
    extra: <String, dynamic>{
      'secure': <Map<String, String>>[],
      ...?extra,
    },
    contentType: 'application/json',
    validateStatus: validateStatus,
  );

  final _queryParameters = <String, dynamic>{
    if (estimateMaxGasAmount != null)
      r'estimate_max_gas_amount': encodeQueryParameter(
          _serializers, estimateMaxGasAmount, const FullType(bool)),
    if (estimateGasUnitPrice != null)
      r'estimate_gas_unit_price': encodeQueryParameter(
          _serializers, estimateGasUnitPrice, const FullType(bool)),
    if (estimatePrioritizedGasUnitPrice != null)
      r'estimate_prioritized_gas_unit_price': encodeQueryParameter(
          _serializers,
          estimatePrioritizedGasUnitPrice,
          const FullType(bool)),
  };

  dynamic _bodyData;

  try {
    const _type = FullType(SubmitTransactionRequest);
    _bodyData = _serializers.serialize(submitTransactionRequest,
        specifiedType: _type);
  } catch (error, stackTrace) {
    throw DioError(
      requestOptions: _options.compose(
        _dio.options,
        _path,
        queryParameters: _queryParameters,
      ),
      type: DioErrorType.unknown,
      error: error,
      stackTrace: stackTrace,
    );
  }

  final _response = await _dio.request<Object>(
    _path,
    data: _bodyData,
    options: _options,
    queryParameters: _queryParameters,
    cancelToken: cancelToken,
    onSendProgress: onSendProgress,
    onReceiveProgress: onReceiveProgress,
  );

  BuiltList<UserTransaction>? _responseData;

  try {
    final rawResponse = _response.data;
    _responseData = rawResponse == null
        ? null
        : _serializers.deserialize(
            rawResponse,
            specifiedType:
                const FullType(BuiltList, [FullType(UserTransaction)]),
          ) as BuiltList<UserTransaction>;
  } catch (error, stackTrace) {
    throw DioError(
      requestOptions: _response.requestOptions,
      response: _response,
      type: DioErrorType.unknown,
      error: error,
      stackTrace: stackTrace,
    );
  }

  return Response<BuiltList<UserTransaction>>(
    data: _responseData,
    headers: _response.headers,
    isRedirect: _response.isRedirect,
    requestOptions: _response.requestOptions,
    redirects: _response.redirects,
    statusCode: _response.statusCode,
    statusMessage: _response.statusMessage,
    extra: _response.extra,
  );
}