Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

contract method calling with 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 :: conditional styled components with media query 
Typescript :: how to restrict alphabets in input field in angular 
Typescript :: call function dynamically typescript 
Typescript :: typescript err type 
Typescript :: typescript keyof typeof 
Typescript :: cannot redeclare block-scoped variable typescript 
Typescript :: typescript object key as enum 
Typescript :: push array elements if not exists mongoose 
Typescript :: verify if object is of a certain type type in typescript 
Typescript :: ordenar por fecha arreglo de objetos typescript 
Typescript :: execute script when c# code gets executed 
Typescript :: salesforce lwc data binding for multiple inputs values 
Typescript :: test coverage when tests are in a different package 
Typescript :: Global CSS cannot be imported from files other than your Custom <App 
Typescript :: split dict into multiple dicts python 
Typescript :: build with tsconfig-paths 
Typescript :: find common elements in two flutter 
Typescript :: chakra ui menu open on hover 
Typescript :: download toasts in django 
Typescript :: Scripts may close only the windows that were opened by them 
Typescript :: typescript syntax 
Typescript :: custom events in unity c# 
Typescript :: typescript export interface array 
Typescript :: react typescript append to array 
Typescript :: firebase typescript 
Typescript :: google sheets k format 
Typescript :: get keys of an array angualr 
Typescript :: ts(2503) 
Typescript :: import validator adonisjs 5 
Typescript :: typescript -g doesnst read tsconfog 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =