Dapp Introduction

Yo @dan-i,
Appreciate your help :slight_smile:

Hey @Marcus_Tang

You need to test your dapp using a server.
run a python simple http server and try there, it will work.

Yo @dan-i,
I don’t quite understand what you mean, cause I am very new towards this kind of things. Appreciate your help.

Hey @Marcus_Tang

Filip explains it step by step here: https://academy.ivanontech.com/products/ethereum-smart-contract-programming-201/categories/1993956/posts/6668112

Let me know if you have questions.

Cheers,
Dani

1 Like

Hey @dan-i,
I kinda understand but may I know how do you open the file in the web?

Hey @Marcus_Tang

Using the Terminal/Powershell you first need to navigate into your project directory, once there you can run your python server.

Let me know if that works :slight_smile:
Dani

1 Like

Hi @dan-i,
May i know where do i get free eth for the ganache network?

Guys, those kind of errors generally thrown because of typos, problem like claimed as “from” parameter which belongs to contractInstance object were never been used in the code, so you go back and forth at the code hundred times but won’t see the f r o m word possibly were staying there as f o r m. Instead of cleaning history of your log, which would necessary later, maybe it’s better to check the code like somebody else’s. fyi

Hey @thecil!
I have a problem with getting my localhost:8000 to save the changes that I make in the code. I put in the changes, than save. Then I reload the webpage. However the changes do not show up. Then I wait for awile (perhaps an hour or so) then the changes show up. Taha tryed to help but he couldn’t figure it out. He allso checked my code and every thing checked out. I was wondering if you could help me with this issue.
Thanks!

Hey @JRB

It might happen and that does not probably indeed depend by your code.
Have you tried to restart the localhost server after a change?

Cheers,
Dani

1 Like

Hi @JRB ,
I had the same problem.
If you are using Chrome, you can click and hold the Refresh icon in front of the address bar, and a box will pop up, and you can choose to “Hard Reload” or even “Empty Cache and Hard Reload”:

1 Like

Hi guys,

I’m having a trouble with my main.js file. Whenever I reload the localport:8000, the alert commands don’t appear like what is seen in Filip’s video. Below is my main.js code:

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

alert("hello testing");

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

    $("#add_data_button").click(inputData)
});

function inputData(){
  alert("Input Data!");
}

And my html:

Is there anything wrong with the linking of the files? Do I have to put the dapp template folder inside the People Folder? I have the dapp template and the People folder under one parent directory.
EDIT: Now the Metamask isn’t working also. An hr ago it was working perfectly fine.

Thank you mentors for being patient! :pray:

Hi guys, in case anyone’s experiencing the same error: I tried duplicating the main.js file and deleted the old one and it worked fine now. Not sure what the problem was lol but it’s not stupid if it works haha

3 Likes

What works for me, if i get any issues, is change the name of the pointer to the js file on the html page, reload the web page so that it registers a change in files (and throws a 404 error in the console as it doesn’t recognise the file) then go and change the name of the actual js file to match the new pointer name (from the html page). Then when you reload the webpage it reads the newly named file completely and correctly. I think it has something to do with the state of the files when you start the server and it doesn’t necessarily pick up changes unless you reload the server or change directory names - not sure really, but changing file names seems to force it to read the file correctly - I guess that’s what you kind of did with duplicating the file. I read in an earlier post something about installing nodemon that will watch for file changes Also, if you make any significant changes or redeploy the contract with a new migration and contract address and so on, Metamask will probably throw errors. I have found just resetting the account in the Metmask settings does the trick. I am now at a point where if my Dapp or Metamask doesn’t work properly after any changes (but I’m sure it should be working) then I just rename the files and reset the Metamask account. Works a treat, I’m sure there are better ways to handle this, but as a noob, I do whatever works for me haha. Good luck

Hi, I’m getting this Metamask error when trying to add a person:

It says “ALERT: Transaction error. An exception in the contract code ocurred”
Inspecting the website, I get this error:


Any help on what could be causing this issue? May it be a Metamask issue?

Here is the code, which should be exactly the same as Filip wrote in the tutorial:

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

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

function inputData(){
  var name = $("#name_input").val();
  var age= $("#age_input").val();
  var height= $("#height_input").val();

  var config = {
    value: web3.utils.toWei("1", "ether")
  }

  contractInstance.methods.createPerson(name, age, height).send(config)
  .on("transactionHash", function(hash){
    console.log(hash);
  })
  .on("confirmation", function(confirmationNr){
    console.log(confirmationNr);
  })
  .on("receipt",function(receipt){
    console.log(receipt);
    alert("Done");
  })
}

Hey @alegarap

I would need to check your contract, it seems like you are hitting a revert().
Can you upload your project to GitHub and give me the link to it?

Happy coding,
Dani

1 Like

did understand why? I had the same problem and just writing py make it work! :slight_smile:

On the Project Setup Video, I could not get the command ‘python - m http.server’ to do anything for me in the command line interface, despite setting the environment variable to the python path.

I am on Windows 10 64x, with Python 3.9 installed.

After some Googling I found the suggestion of using ‘py’ instead of ‘python’ in the command, so:

py - m http.server

This worked for me. Hopefully this will be helpful for someone else.

3 Likes

Good one :slight_smile:

Thanks for sharing,
Dani

2 Likes

i installed Python, however it just isn’t working. Any suggestions?