buildTransactionForFunction method

Future<RawEvmTransaction> buildTransactionForFunction({
  1. required ContractFunctionWithValues function,
  2. required String sender,
  3. EvmFeeInformation<EvmGasPrice>? feeInfo,
  4. BigInt? value,
})

Implementation

Future<RawEvmTransaction> buildTransactionForFunction({
  required ContractFunctionWithValues function,
  required String sender,
  EvmFeeInformation? feeInfo,
  BigInt? value,
}) async {
  final functionData = function.buildDataField();

  if (value != null) {
    assert(
      function.stateMutability == StateMutability.payable,
      'Function is not payable and cannot accept a value',
    );
  } else {
    assert(
      function.stateMutability == StateMutability.nonpayable,
      'Function is payable and requires a value to be sent',
    );
  }

  return await rpc.buildUnsignedTransaction(
    sender: sender,
    recipient: contractAddress,
    feeInfo: feeInfo,
    data: functionData,
    value: value ?? BigInt.zero,
  );
}