Skip to content

Instantly share code, notes, and snippets.

@ac12644
Last active Jan 30, 2022
Embed
What would you like to do?
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