我对前端的 Web 3 功能和 Meta Mask 有疑问
I have a problem with Web 3 capability and Meta Mask In Front End
我在网页上设计了一个用户界面(在 html/java 脚本 中)来显示我的智能合约值。
当其他用户通过其他浏览器访问该网页时,由于缺少数字钱包,他们将无法接收Web 3服务。因为他们没有在他们的网络浏览器上安装钱包。如何在我的网页中放置 Web 3 服务和功能而无需用户安装钱包?
我之前使用的代码如下:
this.web3 = new Web3(this.provider);
//***********
const web3 = new Web3(new Web3.providers.HttpProvider(ethereumUrl))
//****************
new Web3.providers.HttpProvider('https://ropsten.infura.io/' + yourInfuraEndPointKey)
);
//*******************
const web3 = new Web3(provider);
//******
const web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'))
并测试了很多代码。我在这里找不到任何答案。请帮助我。
这是我最后的 Web3 连接代码:
/*this codes in head of web page ant totali it work*/
/*but i want to work in browser that dont install metamask*/
<script src="https://cdn.jsdelivr.net/gh/ethereum/web3.js@1.0.0-beta.36/dist/web3.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/ethereum/web3.js@1.0.0-beta.36/dist/web3.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
<script src="https://unpkg.com/web3@latest/dist/web3.min.js"></script>
<script>
if (typeof window.ethereum !== 'undefined')
{
console.log('MetaMask is installed!');
}else{
console.log('MetaMask not installed!');
alert("Please install Metamsk wallet first, then try again");
}
const accounts = ethereum.request({ method: 'eth_requestAccounts' });
const account = accounts[0];
const showAccount = document.querySelector('.showAccount');
var contractH;
const accountsH = ethereum.request({ method: 'eth_requestAccounts' });
const accountH = accountsH[0];
const showAccountH = document.querySelector('.showAccount');
web333 = new Web3(web3.currentProvider);
//window.web333 = new Web3(new Web3.providers.HttpProvider("https://mainnet.infura.io/<APIKEY>"));
var addressH = "0x624/*My Contract Address*/4135E7a";
var abiH =[/*My ABI*/];
contractH = new web333.eth.Contract(abiH, addressH);
/*and the other code*/
</script>
当我在其他浏览器中 运行 网页时,我看到这个错误:
和我在检查和测试之前关于此页面的详细信息:
this page information
以及 Stack overflow 和其他站点中的每个页面
我在网页上设计了一个用户界面(在 html/java 脚本 中)来显示我的智能合约值。 当其他用户通过其他浏览器访问该网页时,由于缺少数字钱包,他们将无法接收Web 3服务。因为他们没有在他们的网络浏览器上安装钱包。如何在我的网页中放置 Web 3 服务和功能而无需用户安装钱包?
我之前使用的代码如下:
this.web3 = new Web3(this.provider);
//***********
const web3 = new Web3(new Web3.providers.HttpProvider(ethereumUrl))
//****************
new Web3.providers.HttpProvider('https://ropsten.infura.io/' + yourInfuraEndPointKey)
);
//*******************
const web3 = new Web3(provider);
//******
const web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'))
并测试了很多代码。我在这里找不到任何答案。请帮助我。 这是我最后的 Web3 连接代码:
/*this codes in head of web page ant totali it work*/
/*but i want to work in browser that dont install metamask*/
<script src="https://cdn.jsdelivr.net/gh/ethereum/web3.js@1.0.0-beta.36/dist/web3.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/ethereum/web3.js@1.0.0-beta.36/dist/web3.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
<script src="https://unpkg.com/web3@latest/dist/web3.min.js"></script>
<script>
if (typeof window.ethereum !== 'undefined')
{
console.log('MetaMask is installed!');
}else{
console.log('MetaMask not installed!');
alert("Please install Metamsk wallet first, then try again");
}
const accounts = ethereum.request({ method: 'eth_requestAccounts' });
const account = accounts[0];
const showAccount = document.querySelector('.showAccount');
var contractH;
const accountsH = ethereum.request({ method: 'eth_requestAccounts' });
const accountH = accountsH[0];
const showAccountH = document.querySelector('.showAccount');
web333 = new Web3(web3.currentProvider);
//window.web333 = new Web3(new Web3.providers.HttpProvider("https://mainnet.infura.io/<APIKEY>"));
var addressH = "0x624/*My Contract Address*/4135E7a";
var abiH =[/*My ABI*/];
contractH = new web333.eth.Contract(abiH, addressH);
/*and the other code*/
</script>
当我在其他浏览器中 运行 网页时,我看到这个错误:
和我在检查和测试之前关于此页面的详细信息: this page information
以及 Stack overflow 和其他站点中的每个页面