我正在尝试使用需要Metamask扩展的Dapp来访问它.我通过chrome扩展添加了它.我知道如何在硒中添加扩展到chrome实例,但我不知道如何添加密码等.有人可以下载Metamask,并举例说明如何使用它通过selenium传递凭据吗?
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
options.addExtensions(newFile("//Applications//chrome//MetaMask_v3.13.8.crx"));
driver = new ChromeDriver(options);
Run Code Online (Sandbox Code Playgroud) 我正在使用 ethers.js 文档:https ://docs.ethers.io/ethers.js/html/cookbook-providers.html 。设置提供程序时出现错误 -: Uncaught ReferenceError: web3 is not defined 我想将我的去中心化应用程序与元掩码连接。为此,我试图通过根据文档设置提供程序来将元掩码与 ethers.js 连接起来。我使用了 provider = new ethers.providers.Web3Provider(web3.currentProvider)。但是它会为代码中的 web3 对象引发错误。此代码与文档完全相同。但仍然无法正常工作。
//let provider = new ethers.getDefaultProvider('rinkeby');
let provider = new ethers.providers.Web3Provider(web3.currentProvider);
let contract;
let wallet;
let abi = [
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "account",
"type": "address"
},
{
"indexed": false,
"internalType": "string",
"name": "pwd",
"type": "string"
}
],
"name": "Pwd_Assigned",
"type": "event"
},
{
"inputs": [
{
"internalType": "string",
"name": "_passwd",
"type": …Run Code Online (Sandbox Code Playgroud)我正在使用 web3 使用以下方法连接到元掩码
await window.ethereum.request({ method: 'eth_requestAccounts' });
var address = await window.ethereum.request({ method: 'eth_accounts' });
Run Code Online (Sandbox Code Playgroud)
但是当我刷新屏幕时它仍然显示为已连接,我无法在 web3 中找到任何方法将其与 pancackeswap 等网站断开连接
我正在制作一个需要 MetaMask 身份验证的 Chrome 扩展。
我开始将其开发为 Web 应用程序,但作为 chrome 扩展,它无法检测 MetaMask...
这是我现在的网络应用程序代码:
function toggleButton() {
const loginButton = document.getElementById("login-button");
if (!window.ethereum) {
loginButton.innerText = "Install MetaMask";
loginButton.addEventListener("click", () => {
window.open("https://metamask.io");
});
return false;
}
loginButton.addEventListener("click", loginWithMetaMask);
}
async function loginWithMetaMask() {
const accounts = await window.ethereum.request({ method: "eth_requestAccounts" }).catch((e) => {
console.error(e.message);
return;
});
if (!accounts) {
return;
}
const userWallet = document.getElementById("user-wallet");
userWallet.innerText = accounts[0];
}
window.addEventListener("DOMContentLoaded", toggleButton);
Run Code Online (Sandbox Code Playgroud)
有没有办法将 Web 应用程序迁移到 Chrome 扩展程序?
我已经从https://github.com/aragon/metamask-plugin成功安装了扩展程序
启动Electron应用程序时,我可以看到MetaMask插件已加载,但无法使用它.有一些错误:
Uncaught TypeError: global._runtime.onConnect is not a function
at Object.connect (blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:139)
at setupStreams (blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:216)
at Object.<anonymous> (blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:187)
at Object.3../lib/extension (blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:265)
at s (blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:1)
at e (blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:1)
at blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:1
connect @ blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:139
setupStreams @ blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:216
(anonymous) @ blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:187
3../lib/extension @ blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:265
s @ blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:1
e @ blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:1
(anonymous) @ blob:file:///c13a5138-3758-47ae-a481-a163d7aa6a19:1
Run Code Online (Sandbox Code Playgroud)
和
App.js:49 Uncaught TypeError: window._setupMetaMaskPageStream is not a function
at onMetaMaskLoad (http://localhost:1212/dist/renderer.dev.js:1081:14)
at onMetaMaskLoad (http://localhost:1212/dist/renderer.dev.js:19790:30)
at Object.ReactErrorUtils.invokeGuardedCallback (webpack:///./node_modules/react-dom/lib/ReactErrorUtils.js?:69:16)
at executeDispatch (webpack:///./node_modules/react-dom/lib/EventPluginUtils.js?:85:21)
at Object.executeDispatchesInOrder (webpack:///./node_modules/react-dom/lib/EventPluginUtils.js?:108:5)
at executeDispatchesAndRelease (webpack:///./node_modules/react-dom/lib/EventPluginHub.js?:43:22)
at …Run Code Online (Sandbox Code Playgroud) 我需要在以太坊中调用合约中的方法,而不使用 MetaMask。我使用 Infura API 并尝试从最近使用 web3.eth.create() 方法创建的帐户调用我的方法。该方法返回如下对象:
{
address: "0xb8CE9ab6943e0eCED004cG5834Hfn7d",
privateKey: "0x348ce564d427a3311b6536bbcff9390d69395b06ed6",
signTransaction: function(tx){...},
sign: function(data){...},
encrypt: function(password){...}
}
Run Code Online (Sandbox Code Playgroud)
我还使用 infura 提供商:
const web3 = new Web3(new Web3.providers.HttpProvider(
"https://rinkeby.infura.io/5555666777888"
))
Run Code Online (Sandbox Code Playgroud)
所以,当我尝试这样写时:
contract.methods.contribute().send({
from: '0xb8CE9ab6943e0eCED004cG5834Hfn7d', // here I paste recently created address
value: web3.utils.toWei("0.5", "ether")
});
Run Code Online (Sandbox Code Playgroud)
我有这个错误:
错误:给定选项和默认选项中均未指定“发件人”地址。
如果我把它写在选项中怎么可能不是来自地址from?
PS 使用 Metamask 我的应用程序运行良好。但是当我从 MetaMask 注销并尝试创建新帐户并使用它时,我遇到了这个问题。
我正在将 WalletConnect 集成到 React DApp 中,但是我得到了
this.send 不是一个函数
我已确定问题出在 WalletConnectProvider 上,但我已遵循其文档中提到的相同步骤。
请检查我的代码并让我知道如何解决此问题。谢谢。
import WalletConnectProvider from '@walletconnect/web3-provider';
import config from './config';
import Web3 from 'web3';
export const walletConnect = async (setAddr) => {
// Create WalletConnect Provider
const provider = new WalletConnectProvider({
infuraId: config.tokenContract.infuraKey, // Required
});
// Enable session (triggers QR Code modal)
await provider.enable();
console.log('provider', provider);
if (provider.connected) {
console.log('wallet connect address', provider.accounts[0]);
setAddr(provider.accounts[0]);
}
// Create Web3
const web3 = new Web3(provider);
console.log('web3', web3);
const _contract = new …Run Code Online (Sandbox Code Playgroud) 上周 Metamask 推出了一个名为“wallet_addEthereumChain”的新功能,该功能允许用户在出现提示时自动将新的 Etheruem RPC 添加到他们的钱包中。此功能还允许用户更改他们连接的网络,例如,如果我已经将 Binance Smart Chain 连接到元掩码,则调用 wallet_addEthereumChain 将活动网络更改为 BSC。但是,在为以太坊链尝试此操作时,会出现无法添加主网 RPC 的错误。我已经使用以下代码从以太坊主网更改为币安智能链,它工作正常: switchToBinance: async function () {
let ethereum = window.ethereum;
const data = [{
chainId: '0x38',
chainName: 'Binance Smart Chain',
nativeCurrency:
{
name: 'BNB',
symbol: 'BNB',
decimals: 18
},
rpcUrls: ['https://bsc-dataseed.binance.org/'],
blockExplorerUrls: ['https://bscscan.com/'],
}]
/* eslint-disable */
const tx = await ethereum.request({method: 'wallet_addEthereumChain', params:data}).catch()
if (tx) {
console.log(tx)
}
},
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试 Exact 时,metamask 抛出一个异常,说我无法添加主网 RPC:switchToEthereum: async function () {
let ethereum = window.ethereum;
const data = …Run Code Online (Sandbox Code Playgroud) 我正在尝试运行一个基本程序来检测用户是否安装了 window.ethereum。当我运行我的程序时,我得到“@metamask/detect-provider:无法检测window.ethereum”,即使我在浏览器中安装并运行了Metamask。有人遇到过类似的问题吗?提前致谢。
JavaScript:
import detectEthereumProvider from '@metamask/detect-provider';
const provider = await detectEthereumProvider();
if (provider) {
console.log('Ethereum successfully detected!');
})
} else {
console.error('Please install MetaMask!', error);
}
Run Code Online (Sandbox Code Playgroud) 我必须从前端发送多个交易,通常每笔交易都要求用户在 MetaMask 上签名。有没有办法在 MetaMask 中一次对所有交易进行签名,而不是对所有交易都弹出窗口?
metamask ×10
ethereum ×5
javascript ×3
blockchain ×2
reactjs ×2
web3js ×2
automation ×1
electron ×1