ETHTransactionBuilder.contract constructor

ETHTransactionBuilder.contract({
  1. required ETHAddress from,
  2. required ETHAddress contractAddress,
  3. required BigInt value,
  4. required BigInt chainId,
  5. required AbiFunctionFragment function,
  6. required List functionParams,
  7. String? memo,
  8. ETHTransactionType? transactionType,
})

Factory constructor for creating a contract interaction transaction.

Implementation

factory ETHTransactionBuilder.contract(
    {required ETHAddress from,
    required ETHAddress contractAddress,
    required BigInt value,
    required BigInt chainId,
    required AbiFunctionFragment function,
    required List<dynamic> functionParams,
    String? memo,
    ETHTransactionType? transactionType}) {
  final contractData = function.encode(functionParams);
  final List<int> data = memo == null ? [] : StringUtils.toBytes(memo);
  if (value > BigInt.zero) {
    if (function.stateMutability != null &&
        function.stateMutability != StateMutability.payable) {
      throw const ETHPluginException(
          "For calling non-payable methods, the transaction value must be set to zero.");
    }
  }
  return ETHTransactionBuilder._(
      contractAddress,
      from,
      value,
      [...contractData, ...data],
      transactionType,
      function,
      functionParams,
      chainId);
}