英文:
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:
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:
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:
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:
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:
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:
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.
答案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!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论