0

dart, web3dart and walletconnect_dart to create a function that connect users wallet and prompt ERC20 token (e.g USDT) approval. But the approve function requires credentials which has privatekey and there's no way to get privatekey from user connection with trustwallet or metamask. How can I bypass the credentials?

import 'package:web3dart/web3dart.dart';
import 'package:erc20/erc20.dart';
import 'package:walletconnect_dart/walletconnect_dart.dart';
import 'package:http/http.dart' as http;

void main() async {
  final wc = WalletConnect(
      bridge: 'https://bridge.walletconnect.org',
      clientMeta: const PeerMeta(
          name: 'My App',
          description: 'An app for converting pictures to NFT',
          url: 'https://walletconnect.org',
          icons: [
            'https://files.gitbook.com/v0/b/gitbook-legacy-files/o/spaces%2F-    LJJeCjcLrr53DcT1Ml7%2Favatar.png?alt=media'
          ]));

  await wc.connect();

  // final client = await wc.createSession();

  final session = await wc.createSession();

  final ethClient = Web3Client(
    session.rpcUrl ?? '',
    http.Client(),
    // session.chainId.toInt(),
  );
  final tokenAddress = EthereumAddress.fromHex('TOKEN_ADDRESS');
  final token = ERC20(address: tokenAddress, client: ethClient);

  final spenderAddress = EthereumAddress.fromHex('SPENDER_ADDRESS');
  final unlimitedAmount = BigInt.from(2).pow(256) - BigInt.one;

  final userAccounts = await session.accounts[0];

  final transaction = await token.approve(
    spenderAddress,
    unlimitedAmount,
    // EtherAmount.inWei(BigInt.one),
  );


  print('Transaction hash: ${transaction.hash}');
}
TylerH
  • 20,799
  • 66
  • 75
  • 101

0 Answers0