1.0.1 • Published 3 years ago

open-contract v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

clean-contract

Easily get public address from active wallet and initialize contract method accessor.🚀

NPM JavaScript Style Guide

Install

npm install --save open-contract

Usage

import React, { useEffect } from 'react'
//import your contract json
import ContractJSON from './build/contracts/MyContract.json' // path to your contract build

import { CleanContract } from 'clean-contract'

export default function App() {
  const [account, setAccount] = useState('')
  const [contract, setContract] = useState(null)
  const [loading, setLoading] = useState(false)

  // get your api and contract address
  const { apiKey, contractAddress } = process.env

  useEffect(() => {
    (async function fetchData() {
      const result = await CleanContract(apiKey, ContractJSON, contractAddress)
      const { account, contract, contractState } = result

      setAccount(account)
      setContract(contract)
      setLoading(contractState)
    })()
  }, [])
  return (
    {
      !loading ? 
      <div>Happy Hacking!🚀</div>: 
      <h1> Loading... </h1>
    }
  )
}
1.0.1

3 years ago

1.0.0

3 years ago