parv3213 / GargToken-ICO-Sale

An ERC-20 Token ICO Sale
MIT License
16 stars 14 forks source link

Network not detected #11

Open id104335409 opened 1 year ago

id104335409 commented 1 year ago

Hi, Parv I am getting the Network not detected error upon opening the DAPP.

const tokenData = Token.networks[networkId]; if (tokenData) { const tokenContract = await new web3.eth.Contract(Token.abi, tokenData.address); const tokenBalance = await tokenContract.methods.balanceOf(accounts[0]).call(); setTokenBalance(tokenBalance.toString()); } else { window.alert("Token Network not detected"); }

    const tokenSaleData = TokenSale.networks[networkId];
    if (tokenSaleData) {
        const tokenSaleContract = new web3.eth.Contract(TokenSale.abi, tokenSaleData.address);
        setTokenSale(tokenSaleContract);
        let tokenPrice = await tokenSaleContract.methods.tokenPrice().call();
        tokenPrice = await web3.utils.fromWei(tokenPrice.toString(), "ether");
        setTokenPrice(tokenPrice.toString());
        const _tokensSold = await tokenSaleContract.methods.tokensSold().call();
        setTokenSold(_tokensSold.toString());
    } else {
        window.alert("TokenSale Network not detected");

What do I need to change to fix this error? I have connected Metamask to a Ganache blockchain already, but there was no Metamask popup.

parv3213 commented 1 year ago

Make sure you have deployed the contracts on your local chain, and that you are using these for the UI.

On Wed, Jun 14, 2023 at 7:55 PM id104335409 @.***> wrote:

Hi, Parv I am getting the Network not detected error upon opening the DAPP.

const tokenData = Token.networks[networkId]; if (tokenData) { const tokenContract = await new web3.eth.Contract(Token.abi, tokenData.address); const tokenBalance = await tokenContract.methods.balanceOf(accounts[0]).call(); setTokenBalance(tokenBalance.toString()); } else { window.alert("Token Network not detected"); }

const tokenSaleData = TokenSale.networks[networkId]; if (tokenSaleData) { const tokenSaleContract = new web3.eth.Contract(TokenSale.abi, tokenSaleData.address); setTokenSale(tokenSaleContract); let tokenPrice = await tokenSaleContract.methods.tokenPrice().call(); tokenPrice = await web3.utils.fromWei(tokenPrice.toString(), "ether"); setTokenPrice(tokenPrice.toString()); const _tokensSold = await tokenSaleContract.methods.tokensSold().call(); setTokenSold(_tokensSold.toString()); } else { window.alert("TokenSale Network not detected");

What do I need to change to fix this error? I have connected Metamask to a Ganache blockchain already, but there was no Metamask popup.

— Reply to this email directly, view it on GitHub https://github.com/parv3213/GargToken-ICO-Sale/issues/11, or unsubscribe https://github.com/notifications/unsubscribe-auth/AK57PMRYWUPNT7I4O2PGMF3XLHCXDANCNFSM6AAAAAAZGORM5U . You are receiving this because you are subscribed to this thread.Message ID: @.***>

-- Regards Parv Garg