approveToken method
Implementation
Future<DC<Exception, Stream<SmartWalletEvent>>> approveToken(
EthPrivateKey credentials,
String tokenAddress,
String spender,
String value, {
Map<String, dynamic>? transactionBody,
}) async {
final tokenDetailsRes = await ContractsUtils.getERC20TokenDetails(
web3client,
EthereumAddress.fromHex(tokenAddress),
);
final BigInt amount = AmountFormat.toBigInt(
value,
tokenDetailsRes.decimals,
);
final String walletModule = 'TransferManager';
final String methodName = 'approveToken';
final String data = ContractsUtils.encodedDataForContractCall(
walletModule,
EthereumAddress.fromHex(smartWallet.walletModules.transferManager),
methodName,
[
EthereumAddress.fromHex(smartWallet.smartWalletAddress),
EthereumAddress.fromHex(tokenAddress),
EthereumAddress.fromHex(spender),
amount,
],
include0x: true,
);
final String nonce = await _getNonce();
final String signature = ContractsUtils.signOffChain(
credentials,
smartWallet.walletModules.transferManager,
smartWallet.smartWalletAddress,
data,
nonce,
);
final Relay relayDto = Relay(
walletModuleAddress: smartWallet.walletModules.transferManager,
walletAddress: smartWallet.smartWalletAddress,
data: data,
nonce: nonce,
methodName: methodName,
signature: signature,
walletModule: walletModule,
transactionBody: transactionBody,
);
return _relay(relayDto);
}