simolus3 / web3dart

Ethereum library, written in Dart.
MIT License
442 stars 270 forks source link

Allowance Approval #156

Closed nomanmurtaza786 closed 3 years ago

nomanmurtaza786 commented 3 years ago

Hi Simon, Any idea how can I send Allowance approval?

https://0x.org/docs/guides/how-to-set-your-token-allowances

simolus3 commented 3 years ago

You can use the generated erc20 token from this library:

import 'package:http/http.dart';
import 'package:web3dart/contracts/erc20.dart';
import 'package:web3dart/web3dart.dart';

Future<void> main() async {
  final client = Web3Client(yourClient, Client());
final usdcContract = Erc20(
    address: EthereumAddress.fromHex(usdcAddress),
    client: client,
    chainId: 1);
final maxAmount = BigInt.two.pow(256) - BigInt.one;
await usdcContract.approve(yourAllowanceTarget, maxAmount,
    credentials: yourCredentials);
}