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) ::
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) ::
@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.
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();
}
Yes!! Fantastic Toby_KâŚ
Good job!
Ivo
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
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!
Alessandro
Hi, I had to write py instead of python.
Greetings
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).
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.
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
@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
@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 , 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
};
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