interactWithContract method
- required String contractAddress,
- required LocalContractFunctionWithValues function,
- required String sender,
- required Uint8List seed,
- required EvmFeeInformation<
EvmGasPrice> ? feeInfo, - BigInt? value,
Interact with Contract
Implementation
Future<String> interactWithContract({
required String contractAddress,
required LocalContractFunctionWithValues function,
required String sender,
required Uint8List seed,
required EvmFeeInformation? feeInfo,
BigInt? value,
}) async {
final valid = switch ((function.stateMutability, value)) {
(StateMutability.nonpayable, BigInt? value) => value == null ||
value == BigInt.zero, // If nonpayable, value must be 0 or null
(StateMutability.payable, BigInt? value) =>
value != null && value != BigInt.zero, // If payable, value must be set
_ => false,
};
assert(valid, "Invalid value for state mutability of function");
final data = function.buildDataField();
return await buildAndBroadcastTransaction(
sender: sender,
recipient: contractAddress,
seed: seed,
feeInfo: feeInfo,
data: data,
value: value ?? BigInt.zero,
);
}