xclud / dart_erc20

Interface of the ERC20 standard as defined in the EIP-20 Token Standard.
https://pub.dev/packages/erc20/
MIT License
5 stars 3 forks source link

Approve with WalletConnect session? #1

Open LongTien15 opened 2 years ago

LongTien15 commented 2 years ago

I'm connecting to metamask app via wallet_connect_dart and want to swap DAI to ETH, so i want metamask to approve the smart contract to have some DAI but i dont know how ?

xclud commented 2 years ago

Hi, You need to create an ERC20 object with DAI smart contract as the address.

final dai = ERC20(
    address: EthereumAddress.fromHex(
        '0x6b175474e89094c44da98b954eedeac495271d0f'),
    client: client,
);

Then call dai.balanceOf.

Please look at the example usage in the README.md file.

Does this solve your problem?

LongTien15 commented 2 years ago

The client is from infuria node right? but i'm connecting to Metamask mobile app with this package https://pub.dev/packages/walletconnect_dart. So how can i use your package with metamask connection? I'm trying to swap erc20 tokens with Uniswap smart contract

LongTien15 commented 2 years ago

` Future transferTokensToSmartContract(List args) async { DeployedContract contract = await getContract(erc20ContractAddress, erc20ContractAbi); print(contract.address); ContractFunction transferFunc = contract.function('transferFrom'); // ContractFunction symbol = contract.function('symbol'); return transferFunc.encodeCall(args); }

var xx = await uniSc.transferTokensToSmartContract([ EthereumAddress.fromHex(session.accounts.first), EthereumAddress.fromHex('0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D'), BigInt.from(0.00001 * pow(10, 18)), ]);

    var a = await EthereumWalletConnectProvider(connector).sendTransaction(
        from: session.accounts[0],
        to: '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D',
        data: xx,
        value: BigInt.from(0.00001 * pow(10, 18)),
        gas: 1000000,
        gasPrice: BigInt.from(900000));

` This is what is do

xclud commented 2 years ago

If you want to check if the wallet has some DIAs, it doesn't matter where you are querying the account balance. Infura in the example can be replaced with anything.

LongTien15 commented 2 years ago

i want to swap dai for eth through uniswap v2 smart contract. and i can't access the amount of dai in my metamask wallet