Blockchain newbie.
If I place the contract JS in my React App, MetaMask always starts when the Dapp loads.
import donboard from "./donboard";
However, if I remove the import line, I can rely on the below code to help me connect with MetaMask when user clicks the button.
onSubmit = async (event) => {
event.preventDefault();
if (window.ethereum) {
window.web3 = new Web3(window.ethereum);
try {
window.ethereum.enable();
const accounts = await window.ethereum.request({ method: 'eth_accounts' });
const account = accounts[0];
this.setState({ account });
console.log("async onSubmit: " + account);
} catch (err) {
console.log("not connected-onSubmit: " + err);
}
}};
As I will need the contract JS once user is connected, how can I resolve this problem?
Thanks.