Skip to content

Instantly share code, notes, and snippets.

@ac12644
Last active January 30, 2022 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ac12644/4ae75f9dcbb21819490cc70551be7b51 to your computer and use it in GitHub Desktop.
Save ac12644/4ae75f9dcbb21819490cc70551be7b51 to your computer and use it in GitHub Desktop.
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