WalletConnect / Web3ModalFlutter

The Web3Modal for WalletConnect built using Flutter.
https://pub.dev/packages/web3modal_flutter
Apache License 2.0
44 stars 44 forks source link

Redirection issue while execute mint function in flutter App when I am connected with Metamask wallet #125

Closed chetanukani closed 6 months ago

chetanukani commented 6 months ago

I am using the web3modal wallet connect function in my Flutter app. When I connect with metamask using web3Modal in flutter and select metamask wallet then it redirects to metamask and initializes the connection request. So it working fine, but after connection with the wallet, when I try to mint NFT then the Metamask request is coming in the MetaMask App but not able to directly redirect when I click on mint. Here is my mint function code snippet

Future<void> _mintToken() async {
  String data =
  await DefaultAssetBundle.of(context).loadString("assets/abi.json");
  try {
    final deployedContract = DeployedContract(
      ContractAbi.fromJson(
        data, // ABI object
        'Ark',
      ),
      EthereumAddress.fromHex([DEPLOYED_CONTRACT_ADDRESS]),
    );

    var result = await _w3mService.requestWriteContract(
        deployedContract: deployedContract,
        functionName: 'safeMint',
        rpcUrl: 'https://rpc-amoy.polygon.technology',
        parameters: [
          "TOKEN_URI",
          [
            EthereumAddress.fromHex(
                "COLLABORATOR_ADDRESS")
          ]
        ],
        topic: _w3mService.session!.topic.toString(),
        chainId: 'eip155:$_chainId',
        transaction: Transaction(
          from: EthereumAddress.fromHex(_w3mService.session?.address ?? ''),
        ));
  } catch (e) {
    print(e);
    print("---clickevent error ${e}");
  }
}
quetool commented 6 months ago

Hello @chetanukani! Any error that you may see in the console perhaps?

chetanukani commented 6 months ago

Hello @quetool I am not getting errors from the console log as well. And also provides some examples of how we can integrate gas estimation functions for sending transactions in smart contracts for flutter. So, if a smart contract throws an error then we can catch it from gas estimation before requestWriteContract function. Thank you!

chetanukani commented 6 months ago

I got the solution of redirection hence closing this issue

quetool commented 6 months ago

Wonderful @chetanukani! Do you mind sharing the answer in case is useful for other people?

chetanukani commented 6 months ago

Yehh! @quetool I got the solution from previously closed issues. We just call _w3mService.launchConnectedWallet(); this function after our write contract function.