'how to connect provider via Metamask?
I am working on a project, i need to connect provider via MetaMask, need help regarding this. const providerrinkeby = new ethers.providers.Web3Provider(window.ethereum); i tried this code but this is not working. I need to connect provider via Metamask. thanks,
Solution 1:[1]
Try this code:
const provider = new ethers.providers.Web3Provider(window.ethereum, "any");
const signer = provider.getSigner();
const iface = new ethers.utils.Interface(this.getABI());
const tx = {
to: this.contractAddress,
gasPrice: this.gasPrice,
gasLimit: this.gasLimit,
data: iface.encodeFunctionData("send(address,string)", [
this.address, "hello"
])
};
signer.sendTransaction(tx)
.then(() => console.log("%c tx was sent", "color: #009900"))
.catch(() => console.log("%c tx wasn't sent", "color: #FF0000"));
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Silvio Guedes |