callDelegatedContract method

Future<String> callDelegatedContract({
  1. required String contractAddress,
  2. required String functionSignature,
  3. required List args,
  4. BigInt? value,
  5. BigInt? gasLimit,
  6. BigInt? maxFeePerGas,
  7. BigInt? maxPriorityFeePerGas,
})

Calls a method on a delegated contract.

This allows calling contract methods as if the EOA has the contract's code.

Implementation

Future<String> callDelegatedContract({
  required String contractAddress,
  required String functionSignature,
  required List<dynamic> args,
  BigInt? value,
  BigInt? gasLimit,
  BigInt? maxFeePerGas,
  BigInt? maxPriorityFeePerGas,
}) async {
  // Encode the function call
  final data = _encodeFunctionCall(functionSignature, args);

  // Create authorization for the contract
  final currentNonce = await getTransactionCount(address, 'pending');
  final authorization = await createAuthorization(
    contractAddress: contractAddress,
    nonce: currentNonce,
  );

  // Send EIP-7702 transaction
  return sendEip7702Transaction(
    to: address, // Call to self with delegated code
    value: value,
    data: data,
    authorizationList: [authorization],
    gasLimit: gasLimit,
    maxFeePerGas: maxFeePerGas,
    maxPriorityFeePerGas: maxPriorityFeePerGas,
  );
}