Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

ether.js

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 :: typescript pick type from interface 
Typescript :: typescript type from array 
Typescript :: serverless.ps1 cannot be loaded because running scripts is disabled on this system. 
Typescript :: property does not exist on type any typescript 
Typescript :: typescript parameter function type 
Typescript :: Jquery hide() all elements with certain class except one 
Typescript :: multiple where statements sql 
Typescript :: ERROR TypeError: this.element.children.forEach is not a function 
Typescript :: selenium multiple elements with same class name python 
Typescript :: typescript array of string array 
Typescript :: path para imports firebase firestore 
Typescript :: How to Convert MATLAB Scripts to Python 
Typescript :: how to set date axes limits in matplotlib plot 
Typescript :: native base 
Typescript :: latest unity version that supports 32 bit 
Typescript :: add custom function to google sheets 
Typescript :: how to add alias to my hosts in ansible hosts 
Typescript :: print all alphabets from a to z in java 
Typescript :: import ts in html 
Typescript :: None of the following functions can be called with the arguments supplied. makeText(Context!, CharSequence!, Int) defined in android.widget.Toast makeText(Context!, Int, Int) defined in android.widget.Toast 
Typescript :: TypeScript Example Code Snippet 
Typescript :: restaurants near me 
Typescript :: typescript readonly 
Typescript :: object is possibly 
Typescript :: window object 
Typescript :: typescript vite static assets 
Typescript :: using method parameters in a guard nestjs 
Typescript :: idle angular 15 menute 
Typescript :: typescript class import csv file 
Typescript :: requestRandomness 3 arguments given but expected 2 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =