MetaMask SDK 弹出窗口显示,即使我已安装了扩展。

huangapple go评论119阅读模式
英文:

MetaMask SDK popup shows even if i have the extension

问题

I am making a DAPP using React Vite, and i want to switch from using window.ethereum to MMSDK.

Here is my github branch for migrating to MMSDK.

So, what happens is that even if I have the extension it opens the popup when the Submit Button is clicked.

Here are the screenshots for this:

My Extenstion:

MetaMask SDK 弹出窗口显示,即使我已安装了扩展。

If I click Submit:

There are no errors but the popup comes even though I have the extension.

Also, there is a warning when the button is clicked:

MetaMask SDK 弹出窗口显示,即使我已安装了扩展。

MetaMask SDK 弹出窗口显示,即使我已安装了扩展。

That is the main problem, but also if I click Install Metamask Extenstion it does not open the chrome extenstion page; instead it gives this error:

MetaMask SDK 弹出窗口显示,即使我已安装了扩展。

This not working code is also deployed here, if you want to try it on your device.

Here is my submit function:

  1. const handleMethodSubmit = async (methodName, params, stateMutability) => {
  2. try {
  3. const method = contract.methods[methodName];
  4. const provider = MMSDK.getProvider();
  5. const accounts = await provider.request({
  6. method: "eth_requestAccounts",
  7. params: [],
  8. });
  9. const account = accounts[0];
  10. console.log(account);
  11. if (stateMutability === "view") {
  12. const result = await method(...params).call({
  13. from: account,
  14. });
  15. console.log("Method result:", result);
  16. log("Method result: " + result);
  17. } else {
  18. const gasEstimate = await method(...params).estimateGas({
  19. from: account,
  20. });
  21. const transaction = {
  22. from: account,
  23. to: contractAddress,
  24. data: method(...params).encodeABI(),
  25. gas: gasEstimate.toString(),
  26. value: "0x0",
  27. maxFeePerGas: "0x5F5E100",
  28. maxPriorityFeePerGas: "0x5F5E100",
  29. chainId: "0xaa36a7",
  30. };
  31. const result = await provider.request({
  32. method: "eth_sendTransaction",
  33. params: [
  34. {
  35. ...transaction,
  36. feeMarketBid: {
  37. maxFeePerGas: transaction.maxFeePerGas,
  38. maxPriorityFeePerGas:
  39. transaction.maxPriorityFeePerGas,
  40. },
  41. },
  42. ],
  43. });
  44. console.log("Transaction receipt:", result);
  45. log("Transaction receipt: " + result);
  46. }
  47. } catch (error) {
  48. console.error("Error executing method:", error);
  49. log("Error executing method: " + error);
  50. }
  51. };

If you want the full code it is on my github.

At last, I want to mention that on my laptop the test dapp given by MetaMask works well.

PS: Also if you want to checkout my deployed project without MMSDK, it is here.

英文:

I am making a DAPP using React Vite, and i want to switch from using window.ethereum to MMSDK.

Here is my github branch for migrating to MMSDK.

So, what happens is that even if I have the extension it opens the popup when the <kbd>Submit</kbd> Button is clicked.

Here are the screenshots for this:

My Extenstion:

MetaMask SDK 弹出窗口显示,即使我已安装了扩展。

If I click <kbd>Submit</kbd>:

There are no errors but the popup comes even though I have the extension.

Also, there is a warning when the button is clicked:

MetaMask SDK 弹出窗口显示,即使我已安装了扩展。

MetaMask SDK 弹出窗口显示,即使我已安装了扩展。

That is the main problem, but also if I click <kbd>Install Metamask Extenstion</kbd> it does not open the chrome extenstion page; instead it gives this error:

MetaMask SDK 弹出窗口显示,即使我已安装了扩展。

This not working code is also deployed here, if you want to try it on your device.

Here is my submit function:

  1. const handleMethodSubmit = async (methodName, params, stateMutability) =&gt; {
  2. try {
  3. const method = contract.methods[methodName];
  4. const provider = MMSDK.getProvider();
  5. const accounts = await provider.request({
  6. method: &quot;eth_requestAccounts&quot;,
  7. params: [],
  8. });
  9. const account = accounts[0];
  10. console.log(account);
  11. if (stateMutability === &quot;view&quot;) {
  12. const result = await method(...params).call({
  13. from: account,
  14. });
  15. console.log(&quot;Method result:&quot;, result);
  16. log(&quot;Method result: &quot; + result);
  17. } else {
  18. const gasEstimate = await method(...params).estimateGas({
  19. from: account,
  20. });
  21. const transaction = {
  22. from: account,
  23. to: contractAddress,
  24. data: method(...params).encodeABI(),
  25. gas: gasEstimate.toString(),
  26. value: &quot;0x0&quot;,
  27. maxFeePerGas: &quot;0x5F5E100&quot;,
  28. maxPriorityFeePerGas: &quot;0x5F5E100&quot;,
  29. chainId: &quot;0xaa36a7&quot;,
  30. };
  31. const result = await provider.request({
  32. method: &quot;eth_sendTransaction&quot;,
  33. params: [
  34. {
  35. ...transaction,
  36. feeMarketBid: {
  37. maxFeePerGas: transaction.maxFeePerGas,
  38. maxPriorityFeePerGas:
  39. transaction.maxPriorityFeePerGas,
  40. },
  41. },
  42. ],
  43. });
  44. console.log(&quot;Transaction receipt:&quot;, result);
  45. log(&quot;Transaction receipt: &quot; + result);
  46. }
  47. } catch (error) {
  48. console.error(&quot;Error executing method:&quot;, error);
  49. log(&quot;Error executing method: &quot; + error);
  50. }
  51. };

If you want the full code it is on my github.

At last, I want to mention that on my laptop the test dapp given by MetaMask works well.

PS: Also if you want to checkout my deployed project without MMSDK, it is here.

答案1

得分: 0

以下是翻译好的内容:

对于任何遇到这个问题的人,我在MetaMask社区发布了这个问题,有人在那里帮助了我。

所以,这里是那篇帖子的链接。

希望这有所帮助!

英文:

To anyone who is facing this issue, I posted this question on the MetaMask community and someone helped me there.

So, here is the link to that post.

Hope this helps!

huangapple
  • 本文由 发表于 2023年6月27日 18:04:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76563765.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定