callDelegatedContract method
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,
);
}