Hi All,
I know there are many looking to create DApps on Wix using Web3 or Ethereum, I have also been looking into this for a number of months, at present for some reason I am unable to get a website to interact with Metamask however you can engage with the Ethereum Blockchain via Ethers.
I provide the basic page code to get you started, the rest is in the Ethers.js Docs. This I hope will help those who have been trying to do something like this for some time.
Best wishes
Si
const { ethers } = require("ethers"); const network = "homestead"; const provider = ethers.getDefaultProvider(network, {infura: { projectId: 'Your Project ID Here, projectSecret: 'Your Project Secret Here', },}); export async function button1_click() { console.log(ethers); console.log(provider); console.log(await provider.getBlockNumber()); }
you have to import the web3 module to interact and connect with Metamask. It should work the same as most other implementations you can find online. Here is a simple example.
const Web3 = require("web3") const enableEthConnection = async () => { if(window.ethereum) { await window.ethereum.request({method:"eth_requestAccounts"}) window.web3 = new Web3(window.ethereum) return true } return false }
essentially with this code all we are doing is checking if window.ethereum exists. If so we create a new web3 object and send a request to initiate a popup dialogue box. The await window.ethereum.request method is what renders the dialogue box and prompts the user to connect.