buildUnsignedTransaction method

Future<RawEvmTransaction> buildUnsignedTransaction({
  1. required String sender,
  2. required String recipient,
  3. required EvmFeeInformation<EvmGasPrice>? feeInfo,
  4. required Uint8List? data,
  5. required BigInt? value,
  6. List<AccessListItem>? accessList,
})

Used to create a raw Transactions Fetches the gasPrice and gasLimit from the network Fetches the nonce from the network If Transaction Type is not provided, it will use Legacy

Implementation

Future<RawEvmTransaction> buildUnsignedTransaction({
  required String sender,
  required String recipient,
  required EvmFeeInformation? feeInfo,
  required Uint8List? data,
  required BigInt? value,
  List<AccessListItem>? accessList,
}) async {
  final (gasLimit, gasPrice) = await fetchNetworkFees(
    recipient: recipient,
    sender: sender,
    data: data,
    value: value,
    existing: feeInfo,
  );

  final nonce = await performTask(
    (client) => client.getTransactionCount(sender),
  );

  return switch (gasPrice) {
    EvmType2GasPrice fee => RawEVMTransactionType2.unsigned(
        nonce: nonce,
        maxFeePerGas: fee.maxFeePerGas.value,
        maxPriorityFeePerGas: fee.maxPriorityFeePerGas.value,
        gasLimit: gasLimit.toBI,
        to: recipient,
        value: value ?? BigInt.zero,
        data: data ?? Uint8List(0),
        accessList: accessList ?? [],
        chainId: type.chainId,
      ),
    EvmLegacyGasPrice fee => accessList != null
        ? RawEVMTransactionType1.unsigned(
            nonce: nonce,
            gasPrice: fee.gasPrice.value,
            gasLimit: gasLimit.toBI,
            to: recipient,
            value: value ?? BigInt.zero,
            data: data ?? Uint8List(0),
            accessList: accessList,
            chainId: type.chainId,
          )
        : RawEVMTransactionType0.unsigned(
            nonce: nonce,
            gasPrice: fee.gasPrice.value,
            gasLimit: gasLimit.toBI,
            to: recipient,
            value: value ?? BigInt.zero,
            data: data ?? Uint8List(0),
          ),
  };
}