Last active
January 30, 2022 13:59
-
-
Save ac12644/4ae75f9dcbb21819490cc70551be7b51 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState, useEffect } from "react"; | |
import FactoryContract from "./contracts/Factory.json"; | |
import getWeb3 from "./utils/getWeb3"; | |
import "./App.css"; | |
const App = () => { | |
const [state, setState] = | |
useState({web3: null, accounts: null, contract: null}); | |
const [storageValue, setStorageValue] = useState(0); | |
useEffect(() => { | |
const init = async() => { | |
try { | |
const web3 = await getWeb3(); | |
const accounts = await web3.eth.getAccounts(); | |
const networkId = await web3.eth.net.getId(); | |
const deployedNetwork = FactoryContract.networks[networkId]; | |
const instance = new web3.eth.Contract( | |
FactoryContract.abi, | |
deployedNetwork && deployedNetwork.address, | |
); | |
setState({web3, accounts, contract: instance}); | |
} catch(error) { | |
alert( | |
`Failed to load web3, accounts, or contract. | |
Check console for details.`, | |
) | |
console.error(error); | |
} | |
} | |
init(); | |
}, []); | |
const runExample = async () => { | |
const { accounts, contract } = state; | |
}; | |
return( | |
<div> | |
<h1>Fundraiser</h1> | |
</div> | |
); } | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment