Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

calling contract method

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 :: contract method calling with ether.js 
Typescript :: typescript one of the array items 
Typescript :: get object key value typescript 
Typescript :: create react app with redux and typescript 
Typescript :: pass function as argument typescript 
Typescript :: computed vue typescript 
Typescript :: typescript get all enum keys 
Typescript :: Angular import from local library 
Typescript :: concat type typescript 
Typescript :: how to use if statemnts c# 
Typescript :: wc term_exists category 
Typescript :: whats ruby used for 
Typescript :: subscribe form changes 
Typescript :: react native paper 
Typescript :: difference between scripted testing and exploratory testing 
Typescript :: ionic 5 check if string can be a number and then make a number 
Typescript :: How can I call a method every x seconds? 
Typescript :: print query from get_posts wordpress 
Typescript :: promise.all inside useEffect 
Typescript :: typescript interface to http params 
Typescript :: __REDUX_DEVTOOLS_EXTENSION_COMPOSE__ 
Typescript :: Error: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops. 
Typescript :: cacerts default password 
Typescript :: typescript cast string to number 
Typescript :: babel typescript 
Typescript :: angular minus date 
Typescript :: nest js caching 
Typescript :: typescript compile stop using required 
Typescript :: how to implement loudspeaker in web development 
Typescript :: import fonts from angular.json file 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =