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

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

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:

const handleMethodSubmit = async (methodName, params, stateMutability) => {
    try {
        const method = contract.methods[methodName];
        const provider = MMSDK.getProvider();

        const accounts = await provider.request({
            method: "eth_requestAccounts",
            params: [],
        });
        const account = accounts[0];
        console.log(account);

        if (stateMutability === "view") {
            const result = await method(...params).call({
                from: account,
            });
            console.log("Method result:", result);
            log("Method result: " + result);
        } else {
            const gasEstimate = await method(...params).estimateGas({
                from: account,
            });

            const transaction = {
                from: account,
                to: contractAddress,
                data: method(...params).encodeABI(),
                gas: gasEstimate.toString(),
                value: "0x0",
                maxFeePerGas: "0x5F5E100",
                maxPriorityFeePerGas: "0x5F5E100",
                chainId: "0xaa36a7",
            };

            const result = await provider.request({
                method: "eth_sendTransaction",
                params: [
                    {
                        ...transaction,
                        feeMarketBid: {
                            maxFeePerGas: transaction.maxFeePerGas,
                            maxPriorityFeePerGas:
                                transaction.maxPriorityFeePerGas,
                        },
                    },
                ],
            });

            console.log("Transaction receipt:", result);
            log("Transaction receipt: " + result);
        }
    } catch (error) {
        console.error("Error executing method:", error);
        log("Error executing method: " + error);
    }
};

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:

const handleMethodSubmit = async (methodName, params, stateMutability) =&gt; {
		try {
			const method = contract.methods[methodName];
			const provider = MMSDK.getProvider();

			const accounts = await provider.request({
				method: &quot;eth_requestAccounts&quot;,
				params: [],
			});
			const account = accounts[0];
			console.log(account);

			if (stateMutability === &quot;view&quot;) {
				const result = await method(...params).call({
					from: account,
				});
				console.log(&quot;Method result:&quot;, result);
				log(&quot;Method result: &quot; + result);
			} else {
				const gasEstimate = await method(...params).estimateGas({
					from: account,
				});

				const transaction = {
					from: account,
					to: contractAddress,
					data: method(...params).encodeABI(),
					gas: gasEstimate.toString(),
					value: &quot;0x0&quot;,
					maxFeePerGas: &quot;0x5F5E100&quot;,
					maxPriorityFeePerGas: &quot;0x5F5E100&quot;,
					chainId: &quot;0xaa36a7&quot;,
				};

				const result = await provider.request({
					method: &quot;eth_sendTransaction&quot;,
					params: [
						{
							...transaction,
							feeMarketBid: {
								maxFeePerGas: transaction.maxFeePerGas,
								maxPriorityFeePerGas:
									transaction.maxPriorityFeePerGas,
							},
						},
					],
				});

				console.log(&quot;Transaction receipt:&quot;, result);
				log(&quot;Transaction receipt: &quot; + result);
			}
		} catch (error) {
			console.error(&quot;Error executing method:&quot;, error);
			log(&quot;Error executing method: &quot; + error);
		}
	};

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:

确定