Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to connect frontend with solidity

//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()
  }
Comment

PREVIOUS NEXT
Code Example
Javascript :: js detect screen size change 
Javascript :: filter array of objects by another array of objects 
Javascript :: jquery remove option from select by value 
Javascript :: change favicon with javascript 
Javascript :: cypress set viewport 
Javascript :: navigate to url javascript 
Javascript :: horizontal divider react native 
Javascript :: javascript text to clipboard 
Javascript :: battery percentage js 
Javascript :: for elem in list javascript 
Javascript :: onEnter input field react 
Javascript :: js generate id 
Javascript :: discord.js wait seconds 
Javascript :: count the total number of digits of a number in javascript 
Javascript :: acces vue instance from console 
Javascript :: how to add two number using jqueryu 
Javascript :: onMounted 
Javascript :: http request in js 
Javascript :: get child element by class javascript 
Javascript :: set delay react native 
Javascript :: javascript sort array of objects ascending and descending order 
Javascript :: nuxt function call top scroll to top 
Javascript :: loop on objects js 
Javascript :: retour a la ligne <p react 
Javascript :: delayed in js 
Javascript :: js create element 
Javascript :: javacript open url in new tab 
Javascript :: how to view sync storage in chrome 
Javascript :: neo4j delete node by id 
Javascript :: jquery remove all tr from table 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =