How To Connect Frontend With Solidity

[Solved] How To Connect Frontend With Solidity | Solidity - Code Explorer | yomemimo.com
Question : how to connect frontend with solidity

Answered by : joel-mathew

//for reading data
async function YOUR_FUNCTION() { if (typeof window.ethereum !== "undefined") { const provider = new ethers.providers.Web3Provider(window.ethereum) const contract = new ethers.Contract(CONTRACT_ADDRESS, CONTRACT.abi, provider) try { const data = await contract.CONTRACT_FUNCTION() console.log(data) } catch (e) { console.log(e) } }
//writing data
async function requestAccount() { await window.ethereum.request({ method: "eth_requestAccounts" }) }
async function YOUR_FUNCTION() { if (typeof window.ethereum !== 'undefined') { await requestAccount() const provider = new ethers.providers.Web3Provider(window.ethereum) const signer = provider.getSigner() const contract = new ethers.Contract(YOUR_CONTRACT_ADDRESS, CONTRACT.abi, signer) const transaction = await contract.YOUR_CONTRACT('PARAMETER') await transaction.wait() } } //connect wallet async function connectWallet() {
const provider = new ethers.providers.Web3Provider(window.ethereum)
await provider.send("eth_requestAccounts", []);
const signer = provider.getSigner() }

Source : | Last Update : Fri, 13 May 22

Answers related to how to connect frontend with solidity

Code Explorer Popular Question For Solidity