Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

calling contract from ethereum

import { ethers, BigNumber } from 'ethers'


  const [contract, setContract] = useState<any>(undefined)
  const [count, setCount] = useState(BigNumber.from(0))

  useEffect(() => {
    // @ts-ignore
    const provider = new ethers.providers.Web3Provider(window.ethereum)
    setContract(
      new ethers.Contract(
        String(process.env.NEXT_PUBLIC_CONTRACT_ADDRESS),
        contractAbi,
        provider
      )
    )
  }, [])

return (
     <main>
        <button
          className="px-4 bg-red-500"
          onClick={async () => {setCount(await contract.count())}}
        >
          Count
        </button>
        <p>{count.toString()}</p>
      </main>
)

Comment

PREVIOUS NEXT
Code Example
Typescript :: interact with blockchain from nextjs 
Typescript :: conditional styled components with media query 
Typescript :: cannot find file does not match the corresponding name on disk 
Typescript :: nuxt 3 postcss 
Typescript :: typescript convert numer to string 
Typescript :: listobjects vba 
Typescript :: How to combine pdf documents C# 
Typescript :: angular link local library 
Typescript :: dart exit loop 
Typescript :: content script matches all 
Typescript :: serenity.is center open dialog 
Typescript :: create CSS class in directive angular 
Typescript :: sails.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies 
Typescript :: multi select 
Typescript :: [(ngModel)] input error 
Typescript :: outside click hook react 
Typescript :: how to get class weights while using keras imagedatagenerator 
Typescript :: python ffmpeg convert ts to mp4 
Typescript :: print array elements with space c++ 
Typescript :: typescript string 
Typescript :: typescript number to hex string 
Typescript :: typescript to java converter 
Typescript :: download blob typescript 
Typescript :: nuxtServerInit nuxt 3 
Typescript :: typescript react switch case component 
Typescript :: inheritance problem in Dart 
Typescript :: typescript Identical Types 
Typescript :: dividing a number into digits typescript 
Typescript :: elastice search requirements in ubunt 
Typescript :: how to check string array is sorted or not in typescript 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =