Dapp Introduction

Creating A Contract Instance - Dapp Intro

When attempting to start a PYTHON (version 3) web server by entering the appropriate command, it does not start (returned to the UNIX prompt) ::

1 Like

@tical Can you please repost your entire code as described below? There seems to be a number of things missing and I am not sure whether that happened through the pasting.

1 Like

Ass requested below I am re-posting my code below:

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

$(document).ready(function() {
window.ethereum.enable().then(function(accounts){
contractInstance = new web3.eth.Contract(abi, “0xC96737B20852F67C04eC03fe003B818890E950eF”, {from: accounts[0]});
console.log(contractInstance);
});
$("#add_data_button").click(inputData)
});

function inputData(){
alert(“Success”);
var name =$("#name_input").val();
var age =$("#age_input").val();
var height =$("#height_input").val();
}

@Toby_K Thank you :sweat_smile:
I will blame the stress caused by the lockdown :rofl:

1 Like

Yes!! Fantastic Toby_K… :+1:
Good job!

Ivo

You should do as my boy @Toby_K says. He has a point… :wink:


Ivo

1 Like

Hi everyone, I cannot reach the contract in Truffle using localhost in Python.
Metamask is correctly connected, I can see on it the right bilance of accounts[0].
Have you ever seen this favicon.ico error? Can you suggest me want to do?

Thanks!!

Hi @ajcapo90

The fav icon error is not a big deal it’s just your server looking for an icon to display in your browser tab you can solve it using one of this method:

To be able to know why you frontend is not reaching your smart contract you wil have to share your code with us. Can you upload your code on github and share a link here ?
And we ll be able to help you.

Feel free to replay the video you might have missed something :wink:

3 Likes

Hi @gabba,

I used brave and the crypto wallet inside the browser to connect to the contract and with these tools I couldn’t reach it in truffle. So I changed browser and I installed metamask on Google Chrome and I was able to reach the smart contract, even if I saw the favicon.ico error yet. To solve this problem I’ve followed your guide and I’ve added in the HTLM file, below in the header, this code:

<link rel="shortcut icon" href="">

Now all it works correctly, here the final result:

Thanks a lot for your help! :slight_smile:
Alessandro

2 Likes

Hi, I had to write py instead of python.
Greetings

2 Likes

Hi @gabba
the “Get Data” in the HTML can only get the latest person I have created.
What can I do if I want to create a table in my HTML without the “Get Data” button, to list the people I created together with their age and height like below:
I want to be able to get them directly from the blocks in Ganache.

User	Height	Senior
Alice	160	        N
Bob	    170	        Y
Charlie	185	        N
Dan	    180	        N

Hi @Golden_Pig_Coin
It depends how your smart contract is structured.
I ll create an array of person, and two functions:
One to know the size of this array, one to get a person at a specific index
Then when you are starting the frontend you will have to do a for loop to call each person
in the array and store them in a frontend variable (an array of object).

1 Like

Hi @gabba,
thank you!
I will try once my other problem is solved.

1 Like

I had this error on and off all morning. I think it’s related to metamask not finding the account. I found this resolves it:
Set meta mask to connect to a different blockchain like ropsten, then set it back to the local ganache blockchain and change the account to one of the other accounts.

That should be enough to get metamask to reconnect.

1 Like

Hi @gabba, I am unable to view the logging of the contract instance. I have done it before when I first started the course and wanted to review it for my project but cannot redo it even when following filip. MetaMask also doesn’t prompt when launching my localhost:8000

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