@mikekai
You can ask as many question you want
The contract looks fine to me.
Just make sure your are entering amount as 2 ETH
or else will have share Github link to check
@mikekai
You can ask as many question you want
The contract looks fine to me.
Just make sure your are entering amount as 2 ETH
or else will have share Github link to check
@saoirse - sorry I just saw this. Hopefully you have figured it out. If not, in MetaMask, click on an account and select āSettingsā scroll down and find and click on āAdvancedā, scroll and click on āReset Accountā
Regards,
xacatant
This is the dapp I created for Phase 1. It turned out pretty OK I think. Unfortunately the metamask part didnāt get recorded along with it. It looks like I keep clicking on tails but I am actually confirming on metamask.
edit* not sure why but the gif didnāt show up. So I am leaving a link to ImgBB.
hi, i seem to receive an error quite often from metamask:
the annoying this is is that sometimes my dapp does work as expected and then suddenly after a few times of betting it starts returning this error. any advice?
So I reorganized everything and now, it seems to me, itās all working properly. In my first solution there was too much work done in the unsafe front-end in main.js. So in the new version everything that seemed sensitive to me is handled on the contract side, and I also used a mapping and a struct to handle customer information. The ānowā function I also got to work (donāt ask me howāit just suddenly decided to work properly), but during migration test runs, the randomness that it produced was somewhat limited (probably due to insufficient speed in the advance of the block-timeāthatās my guess), and I therefore added another count-variable and then produced the hash of the resulting concatenation. I also added an encoding string as before, but this time as a private variable in the contract. I have no idea how easily a private variable in a contract can be accessed, but as I mentioned before, to the best of my understanding of the properties of the hash function, the encoding string would render the pseudo-random sequence generated by the hash function nearly unbreakable if it could be kept in a safe place like an off-line ledger wallet. In any case, I decided to leave the encoding string in the hash-input in case that it adds a bit of additional safety.
The button for the withrawal of all funds in the contract that you can see in the picture shows up only if the person playing is the contract owner. The corresponding test is also run through the contract rather than main.js so that there is no information about the ownerās address available in the front-end code.
Here is the link to my files on gitHub in case that you want to take a look:
And here is a screen copy of my program in action:
The number line provides a little animation as the numbers cycle through color changes from white or black to red, and as the outcome of the game is indicated by the last number that turns red. The reason for having two input optionsāone for zero and one for oneāis simply that users may want to have that freedom of choice. Mathematically, any two-way bet is always equivalent to a corresponding one-way bet, but as I said, it might be nicer for a user to be able to pick an outcomeāzero or one.
Finally, let me say again, that I greatly appreciated the opportunity to work on this project. I feel that I really learned a lot, and I look forward to the second part using oracles. Thank you!
Thanks! I am excited for the oracle section but it looks scary. haha.
I had a quick question. When migrating a contract to ganache do we add value to the contract via the migration.js file (im using my coin migration file not the intial)? Is it done like this?
const Coinflip = artifacts.require("Coinflip");
module.exports = function(deployer, network,accounts) {
deployer.deploy(Coinflip).then(function(instance){
instance.send({from:accounts[0],value:web3.utils.toWei("5","ether")})
})
};
Looks fine!
Sample code
const Flip = artifacts.require("Flip");
module.exports = function(deployer, network, accounts) {
deployer.deploy(Flip).then(function(instance){
instance.fundContract({value: web3.utils.toWei('2', 'ether')})
});
};
Thank you very much!
Not a lot to show here, I recycled the HTML from the example and thereās basically two functions: One to flip the coin, another to load the contract. The contract also loads 10 ETH on startup and displays the balance at the bottom.
The only thing I couldnāt figure out how to do (not an expert on jquery tbh) is how to display the contract balance when loading the website. Iād really appreciate some help there. In the old course, Filip coded his example so that the contract balance is displayed when Metamask is connected but I just couldnāt figure out how to do this.
Moving on to the next phase!
@Juan_M_Villaverde
Thanks for reaching out!
It will be nice if you can share your code via GitHub link for helping you with displaying contract balance using jquery
@Juan_M_Villaverde
I have done some changes to the Github main.js file.
basically, you will need to add the following lines in your ready function
and create an HTML element in index.html
to input the data into
$(document).ready(function() {
//create variable for contract address balance
var contract_balance = web3.eth.getBalance("your contract address");
//create an element in HTML with id
//add the id of the HTML element below
$("#yourHTMLelementid").html(contract_balance);
Perfect! Thanks Taha. Iāll put this good use. Iām ready to start doing web3 with the integrated oracle already, itās deployed on Ropsten and working as intended after⦠Lots and lots of trials lol!
Hey Taha! How can I call a getter function on loading the contract? reason I ask is the new versionās ābalanceā doesnāt really match the balance on the testnet. Part of the contract balance is reserved for users who won bets so I really need to call the ābalanceā variable and display that on the website.
When I try var contract_balance = contractInstance.methods.getBalance().call(); I just get an error saying contractInstance doesnāt exist.
Thanks!
You have multiples way of doing it, first do you have a method called getBalance in your contract ?
If yes you need to create your
var contract_instance
At the top of your main.js, then you initialize your contract
$(document).ready(function() {
window.ethereum.enable().then(function(accounts){ // window.ethereum.enable brings up the Metamask prompt in the webpage.
contractInstance=new web3.eth.Contract(abi, "0x62E2fF8FbCFa57149c129fd8d66741ABe3735529", {from: accounts[0]}); //This creates an instance of a contract, the argument abi is the functions and variables therein (see abi.js), the second argument is the contract address, as a string. Finally, the third specifies the sender for the contract.
console.log(contractInstance);
});
});
Then you can call this method in your code
var returnValue = contractInstance.methods.getBalance().call();
This function will call your contract and get the value you are returning.
If you want to know the real contract value you should do it the way @Taha described it
var contract_balance = web3.eth.getBalance("your contract address");
If you have a balance variable in your contract which is public you can also call it this way.
var balanceVar = contractInstance.balance.call();
When your variable are declared as public the compiler is creating getter automatically for you.
I hope it helps, if you still have issues please add you solidity contract on github, because you had only pushed the fronted code.