approveTokenAndCallContract method
Future<ISendUserOperationResponse>
approveTokenAndCallContract(
- EthereumAddress tokenAddress,
- EthereumAddress spender,
- BigInt value,
- Uint8List callData, [
- TxOptions? options,
Approves a token for spending and then calls a contract.
This method first approves a certain amount of tokens for a spender and then makes a contract call. It's commonly used in scenarios like interacting with DeFi protocols where a token approval is required before making a transaction.
tokenAddress
is the address of the ERC20 token to be approved.
spender
is the address that will be approved to spend the tokens.
value
is the amount of tokens to be approved for spending.
callData
is the encoded data for the subsequent contract call after approval.
options
provides additional transaction options.
Implementation
Future<ISendUserOperationResponse> approveTokenAndCallContract(
EthereumAddress tokenAddress,
EthereumAddress spender,
BigInt value,
Uint8List callData, [
TxOptions? options,
]) async {
final approveCallData = ContractsUtils.encodeERC20ApproveCall(
tokenAddress,
spender,
value,
);
final calls = [
Call(
to: tokenAddress,
value: BigInt.zero,
data: approveCallData,
),
Call(
to: spender,
value: BigInt.zero,
data: callData,
),
];
return executeBatch(calls, options);
}