callContract method
Calls a function of a smart contract and returns the user operation hash.
This function allows you to call a function on any smart contract using an userOp .
Parameters:
contractAddress: The address of the smart contract to interact with.contractAbi: The JSON ABI (Application Binary Interface) of the smart contract, which defines the methods and data structures of the contract.functionName: The name of the function within the smart contract that you want to call.args: A list of dynamic arguments required for the function call, which should match the function's parameter types as specified in the contract's ABI.currentAddress: The current Ethereum address of the user making the function call.useDefaultPaymaster: An optional boolean indicating whether to use the default paymaster for gas payment. If not provided, it defaults to the value ofthis.usePaymaster.gasPrice: An optional BigInt representing the price (in Wei) that you are willing to pay per unit of gas.gasLimit: An optional BigInt representing the maximum amount of gas that can be consumed by the transaction.
Returns:
- A Future
Implementation
Future<String> callContract({
required String contractAddress,
required String contractAbi,
required String functionName,
required List<dynamic> args,
required String currentAddress,
bool? useDefaultPaymaster,
BigInt? gasPrice,
BigInt? gasLimit,
}) async {
// Get the user operation for the contract function call.
final RPCResult res = await _getContractCallingUserOp(
contractAddress: contractAddress,
contractAbi: contractAbi,
functionName: functionName,
args: args,
useDefaultPaymaster: useDefaultPaymaster ?? this.usePaymaster,
currentAddress: currentAddress,
);
// Fetch the personal signature for the user operation.
final String signature =
await fetchSignature(res.userOpHash!, this.signer, true);
print("Now sending signed op");
// Send the signed user operation to the Ethereum network.
final String userOpHash = await RPCCall().sendSignedOp(
signature,
res.userOp!,
useDefaultPaymaster ?? this.usePaymaster,
this.bundlerURL,
this.entryPointAddress,
this.paymasterConfig,
);
// Return the user operation hash.
return userOpHash;
}