Programming Project - Phase 2

Hey @lohba

Sure I can!
Which function are you calling when the revert message is displayed?
Also please post your github again.

Cheers,
Dani

thank you so much @dan-i, the function I’m calling is flipCoin when the user clicks on the “Place bet!” button

https://github.com/lohba/Coin-Flip-Dapp-v2

@lohba

Your transactions are failing because of the gas set in your js.

var config = {
    value: web3.utils.toWei(betValue.toString(), "ether"),
    gas: 100000, <<-
  };

  contractInstance.methods
    .flipCoin(bet)
    .send(config)

You can see an error in ropsten (below your last transaction):
Screenshot 2021-01-05 at 18.03.28
https://ropsten.etherscan.io/tx/0xf448cf9946c79f1fc319a7cf6d503b24fdb6e206d1d41f185fcd9fe38dfaa322

Try to remove the gas property and you should be fine:

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

I deployed your contract and had some fun (the last failed transaction was a test) :slight_smile:
https://ropsten.etherscan.io/address/0xf87a0412a278e6512570c46589e431af0e0902c7

Le me know,
Dani

Hi @dan-i

My node version is v: 10.21.0. I changed my Infura key but I get the same Infura error. How to solve this?

Thanks @dan-i! It looks good to me! I’m not sure if this was ever brought up before but I’m trying to add the capability to support multiple wallets besides Metamask. I basically want to replicate this pop up when clicking connect https://web3modal.com/ I found a simple library that allows this to work. My question was when adding Web3Modal to my current app, do I replace what is already in the truffle-config.js file with what is displayed in Step 3 found on their github? How can I go about this? Thank you again for you always helpful insights.

https://github.com/Web3Modal/web3modal

Hey @lohba

I never used it but in the documentation you linked is explained how to proceed.
There is indeed a part that only talks about the truffle config file.

Follow their steps and you should be fine!

Happy coding,
Dani

Hi @dan-i

Is there anything wrong with the way I use infura key and project secret? or gas limit? My github

image

Hi @dan-i

I could finally deploy on ropsten!!! I just tried multiple times since morning! However the contract balance does not show in the terminal. Is there anything wrong with my migration file?

Hey @oneworldcoder

Yeah I was sure that you would have been able to deploy.
I faced that issue too and it is related to Infura. There is nothing we can do about it if not waiting patiently until it comes back.
Another solution is to use another testnet instead of Ropsten so that you also learn new things :slight_smile:

Your console.log syntax is wrong, try
console.log(`The contract balance is ${await instance.balance()}`);

Happy coding,
Dani

Hi @dan-i

I changed the syntax however the balance does not show. How to solve this?

image

@oneworldcoder paste your code please

Hi @dan-i

Coinflip.sol , migration.js

const Coinflip = artifacts.require("Coinflip");

module.exports = async function(deployer, network, accounts ) {
  await deployer.deploy(Coinflip);
  const instance = await Coinflip.deployed();
  await instance.addMoney({from: accounts[0], value: web3.utils.toWei("0.5", "ether")});

  console.log("The contract balance is ${await instance.balance()}");
};

The quotation marks you are using are different than the one I posted.

You are using " " but you should use ` `

console.log(`The contract balance is ${await instance.balance()}`);

Hi @dan-i

I changed the quotation marks. I get TypeError: instance.balance is not a function

Hey @oneworldcoder

You do not have any variable called balance in your contract.

What you are trying to do with console.log(`The contract balance is ${await instance.balance()}`); is simply to display the value held by a variable called balance.
Solidity automatically creates a getter function for all its public variables.
Because you don’t have a variable called balance it tells you that balance() is not a function.
Replace balance with the public variable you want to display.

1 Like

My project https://github.com/oneworldcoder/CoinFlip2

Thank you @dan-i and @thecil

2 Likes

Hey @oneworldcoder

I like this modifier, good one

 modifier checkFlip(uint prediction){
       require(msg.value > 0 && msg.value <= (availableMoney / 2));
       require(prediction == 0 || prediction == 1);
       _;

About this function that allows an address to withdraw all the contract balance, should this be onlyOwner?

    function withdrawMoney() public returns(uint) {
       uint toTransfer = availableMoney;
       availableMoney = 0;
       msg.sender.transfer(toTransfer);
       return toTransfer;
   }

I do not see other bugs in your contract anyway, well done.

Dani

1 Like

Hi @dan-i

Yes withdrawMoney should be onlyOwner.

I am thinking of building about 3-4 projects for my github profile. Can you tell me any websites where I can find ideas?

Can you tell me any websites where I can find ideas?

In the blockchain space, ideas are the most valuable “assets” :slight_smile:
Do you have a project that you like?
Do you like decentralised exchanges?

If yes then just play with existing projects and protocols, maybe you can find something interesting to code.

Also check https://gitcoin.co

Keep in mind that this industry is usually extremely open, feel free to join Discord groups and discuss with other devs.

Also make sure you perfectly know web3, write code in js using that library until you master it.

Now you have all the tools you need to read and understand Solidity, take your time, keep study and try to network with valuable people.

Good luck and never give up!

2 Likes

@dan-i @filip

May I know why I cannot call other function within the code inside the __callback(), I have included the Remix screen capture attached.

and here is the github link: https://github.com/kwokkawai/dapp-coinflip.git

contract name: coinflip.sol