Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Problem with the window.ethereum provider #211

Open
laurowrn opened this issue Oct 27, 2021 · 0 comments
Open

Problem with the window.ethereum provider #211

laurowrn opened this issue Oct 27, 2021 · 0 comments

Comments

@laurowrn
Copy link

I'm trying to learn how web3dart works on Flutter Web and I faced this problem: when I execute this code (with the infura provider):

onPressed: () async {
          Client httpClient = Client();
          final web3Client = Web3Client(Constants.infuraProvider, httpClient);

          final contract = DeployedContract(
            ContractAbi.fromJson(Constants.abi, 'TestContract'),
            EthereumAddress.fromHex(Constants.contractAddress),
          );

          final function = contract.function('getBalance');
          final balance = await client.call(contract: contract, function: function, params: []);
          await client.dispose();
          setState(() {
            state = balance[0].toString();
          });
        },

The code worked as expected, but when I changed the provider to the window.ethereum, the contract call doesn't worked at all.

onPressed: () async {
          final eth = window.ethereum;
          if (eth == null) {
            state = 'Connection refused';
            return;
          }

          final client = Web3Client.custom(eth.asRpcService());
          final contract = DeployedContract(
            ContractAbi.fromJson(Constants.abi, 'TestContract'),
            EthereumAddress.fromHex(Constants.contractAddress),
          );
          final function = contract.function('getBalance');
          final balance = await client.call(contract: contract, function: function, params: []);
          await client.dispose();
          setState(() {
            state = balance[0].toString();
          });
        },

I want to know if I am doing something wrong, or if it is a bug with the metamask provider.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant