Dapp Introduction

Hi @mjwatson10
What do you mean by

When your application has been whitelist metamask will not open a prompt to ask you again to accept the connection

1 Like

@gabba I actually was able to fix it, MetaMask wasn’t prompting when I launched my local server. I changed the Title element on my HTML index and saved it and it was working. So i tried repeating it on my project by simply saving my HTML index (I didn’t make any changes this time, just re-saved it) and it worked

1 Like

@gabba sorry to be such a pain, I just keep running into walls. I am not sure what is wrong with my js code on my main.js but my dApp is not working what so ever. I can get metamask to recognize that a transaction is being made when I click either heads or tails but its does not recognize the amount entered from my input element “Bet Amount”. Could you take a look at my code on my gitHub?

Hi @mjwatson10

No worries :wink: , you are not seeing it in metamask because you are sending wei not eth, try with this value
1000000000000000000
you will see 1 ETH
you can also add a minimum amount of gas because your transaction will cost more than the 21000 gas require.

    var config = {
      value: betAmount,
      gas:100000
    };

You can also convert the wei amount into ETH the same way you are doing it in the addFunds method

    var config = {
      value: web3.utils.toWei(betAmount, "ether"),
      gas:100000
    };

2 Likes

Hi @filip,
please help,
I stuck at this point: I can not log out the contractInstance on borwser’s console;
I tried restart Python server, restart Ganache, Migrate People project…, copy abi, copy address…: But nothing works…
Here is my code for main.js:

var web3 = new Web3(Web3.givenProvider);
var contractInstance;

$(document).ready(function() {
    window.ethereum.enable().then(function(accounts){
      contractInstance = new web3.eth.Contract(abi, "0xf7AfB73A7E0284489799959fDf0cf4FCD4babc4b", {from: accounts[0]});
      console.log(contractInstance);
    });
});

Here are error logs from browser console:
DevTools failed to load SourceMap: Could not load content for chrome-extension://gighmmpiobklfepjocnamgkkbiglidom/include.preload.js.map: HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME
DevTools failed to load SourceMap: Could not load content for chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/sourcemaps/contentscript.js.map: HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME
DevTools failed to load SourceMap: Could not load content for chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/sourcemaps/inpage.js.map: HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME
inpage.js:1 MetaMask: MetaMask will soon stop reloading pages on network change.
If you rely upon this behavior, add a ‘networkChanged’ event handler to trigger the reload manually: https://metamask.github.io/metamask-docs/API_Reference/Ethereum_Provider#ethereum.on(eventname%2C-callback)
Set ‘ethereum.autoRefreshOnNetworkChange’ to ‘false’ to silence this warning: https://metamask.github.io/metamask-docs/API_Reference/Ethereum_Provider#ethereum.autorefreshonnetworkchange

c.enable @ inpage.js:1
(anonymous) @ main.js:4
e @ jquery-3.4.1.min.js:2
t @ jquery-3.4.1.min.js:2
setTimeout (async)
(anonymous) @ jquery-3.4.1.min.js:2
c @ jquery-3.4.1.min.js:2
fireWith @ jquery-3.4.1.min.js:2
fire @ jquery-3.4.1.min.js:2
c @ jquery-3.4.1.min.js:2
fireWith @ jquery-3.4.1.min.js:2
ready @ jquery-3.4.1.min.js:2
B @ jquery-3.4.1.min.js:2
DevTools failed to load SourceMap: Could not load content for chrome-extension://gighmmpiobklfepjocnamgkkbiglidom/include.postload.js.map: HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME

I have moved this post there: thanks for reading!
https://forumtest.ivanontech.com/t/creating-contract-instance-main-js-doesnt-affects-html-page/17525/4

Hi @tungtien

I answered to your post on the other topic, i hope we will solve it :wink:

1 Like

Thanks @gabba ! Problem solbed

1 Like

Thanks @gabba, metamask is taking the bet amount now, however it is always taking to transactions.
If I bet .1 eth, it will request two transaction of .1 ether plus the gas. I think I may have the request linking to both functions for heads and tails which is causing the double bet. But cannot figure out how I fix it, this I also think is not allowing me to see whether the bet was won or lost

I got it too. That onerous favicon … I noticed that if I do hard refresh vs. just a regular refresh it appears and disappears whether or not I put the

1 Like

Filip,

I sloved the problem. Python was running after my first installation, but only when I installed it a second time via a different path was I able to establish the local host. These kinds of problems I find very frustrating because there is almost no way figure out what’s going on—it’s all just random experimentation. So far as I can tell I installed Python from the same source but via a different path. I entered just ‘python’ into the power shell as a command and a window opened up to download the Python app. Using that download path via the power shell, the installation was apparently modified and it all worked out. Very strange.

Frank

2 Likes

Hi.

I tried to set up the ganache network in metamask, but the Dapp always tries to connect to a account on the main Network.

How can I fix this?

Here is a github link for my code:

https://github.com/Gusonaj/IvanOntechDappIntroduction

Hi @guso Thanks for reaching out!
in your main.js after Line 1 add:

App.web3Provider = new web3.providers.HttpProvider('http://127.0.0.1:9545');
web3 = new Web3(App.web3Provider);` 

make your your port is 9545 or change it to whatever you are using

It is because in your main.js you are only connecting to your givenProvider and there is no fallback to Ganache.

Source:https://www.trufflesuite.com/docs/truffle/getting-started/truffle-with-metamask

2 Likes

@Taha now i get the error:

Uncaught ReferenceError: App is not defined
at main.js:3

I implemented your code suggestion after line 1 in line 3

Hi @guso

Remove from line 1 to 3

and try this

if(typeof web3 != 'undefined'){
web3 = new Web3(web3.currentProvider);
} else {
web3 = new Web3(new Web3.providers.HttpProvider('http://127.0.0.1:7545'));
}

Make sure the port is correct

1 Like

@Taha I tied that, but then i just get the same problem as at the start and the Dapp still tries to connect to a account on the main Network. Also checked that the port is correct.

1 Like

@guso

in truffle-config.js

module.exports = {
networks: {
development: {
host: “127.0.0.1”,
port: 7545,
network_id: “*” // Match any network id
}
}
};

Add this

also you can try connecting to the main network and while executing transaction check wether its asking for main network or ganache

1 Like

@guso
If its still not working can you elaborate more about when is your dApp trying to connect to the main network, on which instance?

Because executed your code and its runs properly on the ganache :slight_smile:

1 Like

@Taha
It still doesn’t work.
When I open the site the first time it asks me to connect with the main net.

https://forumtest.ivanontech.com/uploads/default/original/2X/b/b498d5b375d1d7318fc8dabd1e3c3bfe98fb58c9.png

If I connect with the main net and try to execute the contract:

@guso
I am able to connect to Ganache directly, didn’t ask for main net

try using another metamask (by reinstalling or another browser)

While execute trans

1 Like