Programming Project - Phase 2

Hi @KryptoS

Can you please clarify your question?
I wrote a long review of your project already :slight_smile:
Programming Project - Phase 2

Hi @dan-i - sorry for the confusion. I meant suggestions on new project ideas. :slight_smile:

Hi @KryptoS

As I told to another student that was asking the same question, ideas are the most valuable asset especially in out field (blockchain development).

I might suggest to look for a project that already exists and then try to replicate in your own personal way.

A good one could be prediction markets for example.
You can bet agains other people the result of a football match, or tomorrow’s weather forecast.

You can create you own defi project by lending money for example.
You own nft.

You have an infinite amount of choices, your imagination is the only limit to what you can do :slight_smile:

Happy coding,
Dani

1 Like

I’m having trouble getting ETH from faucet in ropsten network. Maybe just impatience? A transaction is listed, but it’s not showing up on etherscan.

Hi Dani,

thank you again. This was actually the stepping stone I needed. The dApp is now also working nicely and updating upon the receipt of the event.
If you are interested the whole code can be found here:
https://github.com/rkindle/Coinflip
Pictures:

Thank you very much,
Ralf

:grimacing: :grimacing:
https://github.com/Haysoose/Coinflip-Dapp

Hi everyone, this is my work, so far. It is basically the same dapp as phase 1 but upgraded to support random numbers generated by oracles.

https://github.com/MarcoCovarrubias/CoinBet

The interface is pretty simple and lacks a lot of interactivity (I never have programmed in html and js before) but the fundamentals of this course are all applied successfully.

There is a video in the gitHub repository that shows how the dapp works (https://github.com/MarcoCovarrubias/CoinBet/blob/main/CoinBet.mp4). First the user requests a bet by selecting how much ETH she/he wants to bet, then hit the TOSS THE COIN! button and waits for the transaction to complete, and for the oracle to generate the random number. The output can be seen in the console. The dapp ask to the user to wait for the result and then to check her/his wallet once the result is ready.

The contract address is 0xDa49faCFAB3EC9c5FAc0e00D180FA410C2aC5926

In the repository I did not uploaded the folder node-modules folder as it has a lot of files and gitHub does not allowed me to uploaded it.

Thanks.

1 Like

Here is my source code:
https://bitbucket.org/aiisnotbad/dicecoin

For some reasons it did not work the last time I tested it. Im not sure if the oracle is processing the request this time.

Hey @dan-i

i had some private problems so i didn’t program for a while.
Balance of the contract is 0,15 eth and transaction go through if i bet less then 0.01 but i dont see flip won or lose message anymore and payouts are going to this address 0xCBf1735Aad8C4B337903cD44b419eFE6538aaB40
https://ropsten.etherscan.io/tx/0x59d5e65ce1fcb74784e349b81ff67c455daa07109f5e80b6e4045fbcbfac0a57

What am i doing wrong, a little gudiance will be much appreciated

This is my github https://github.com/Spartak91/Project-coinFlip

Thanks in advance!

hello,

after I deploy my contract in ropsten network I see this error in metamask:

web3.min.js:1 Uncaught (in promise) Error: Returned values aren't valid, did it run Out of Gas?
    at i.decodeParameters (web3.min.js:1)
    at o._decodeMethodReturn (web3.min.js:1)
    at _.outputFormatter (web3.min.js:1)
    at _.formatOutput (web3.min.js:1)
    at u (web3.min.js:1)
    at web3.min.js:1
    at inpage.js:1
    at <anonymous>

can you please help me? I don’t understand what is not working

hi @enrico

In order to help you I need more information.
How can I reproduce the issue? What function are you calling?
Do you have a contract deployed on a testnet that I can check? If yes what’s the address?

Hey @Spartak

Balance of the contract is 0,15 eth and transaction go through if i bet less then 0.01 but i dont see flip won or lose message anymore and payouts are going to this address 0xCBf1735Aad8C4B337903cD44b419eFE6538aaB40

Are you facing an issue with the events?
What’s the address you posted and is it an issue if the payouts go there?

Please give me some context and I will be happy to help.

Regards,
Dani

Hello @dan-i ive been pre occupied on trading for the last month or so… Im now picking away at Phase two now.

Hvae you encountered this error before?

Is it to do with my version of NPM or anything?

Thanks :).

hello,

I’m not calling any function. After I deployed my contract I started the python server and open the dapp webpage. On the console I get this error right away without calling any function.

Last time i deployed the contract it had this address: 0xcB1c2cb823577a88D8D3037aB4F37B9F0E43a92d

this is my contract

import"./Ownable.sol";
import"./provableAPI.sol";

pragma solidity 0.5.16;

 contract coin is Ownable, usingProvable{

    struct player {
      uint amount;                          // amount the player want to bet in ether
      uint bet;                             // what the player want to bet: 0 or 1
      address payable playerAddress;        // address of the player
      string message;                       // message after flip: WIN or LOSE
      uint result;                          // result of the coin flip returned from provable
    }

    uint public balance;                                    // updated balance of the contract
    uint public minBet;                                     // minimum bet set by the owner
    uint256 constant NUM_RANDOM_BYTES_REQUESTED = 1;
    bytes32 queryId;

    event logNewProvableQuery(string description);
    event generateRandomNumber(uint256 randomNumber);

    modifier costs(uint cost){
        require(msg.value >= cost);
        _;
    }

// owner send money to the contract at the moment of deployment
    constructor() public payable{
        require(msg.value >= 1000);
        balance += msg.value;
    }


    mapping (address => player) private players;  // link player to his address
    mapping (bytes32 => player) private playerId; // link player to his queryId
    mapping (address => bool) private waiting;    // link player to his waiting status: true or false



// player set his bet (0 or 1), his bet amount and send that amount to the contract
    function setBet(uint amount, uint bet) public payable costs( (players[msg.sender].amount)*100 ){

        require(waiting[msg.sender] == false);  // player which is waiting for bet result can't bet before to know the result

        waiting[msg.sender] = true;  // once th player set the bet his waiting status is set to true

        balance += msg.value;

        player memory newPlayer;
        newPlayer.amount = amount;
        newPlayer.bet = bet;
        newPlayer.playerAddress = msg.sender;

        insertPlayer(newPlayer);   // players[msg.sender] = newPlayer

// require that the amount bet is lower than half balance
        require((players[msg.sender].amount)*100 <= balance/2, "Bet over contract funds");


        uint256 QUERY_EXECUTION_DELAY = 0;
        uint256 GAS_FOR_CALLBACK = 20000;
        queryId = provable_newRandomDSQuery(
        QUERY_EXECUTION_DELAY,
        NUM_RANDOM_BYTES_REQUESTED,
        GAS_FOR_CALLBACK
        );

        playerId[queryId] = newPlayer;
    }


    function __callback(bytes32 _queryId, string memory _result, bytes memory proof) public {
        require(msg.sender == provable_cbAddress()); //l'address deve essere quello dell'oracle

        uint256 randomNumber = uint256(keccak256(abi.encodePacked(_result))) % 2;

        emit generateRandomNumber(randomNumber);

        if(randomNumber == (playerId[_queryId].bet)){

        balance = balance - (playerId[_queryId].amount)*100*2;
        playerId[_queryId].playerAddress.transfer( (playerId[_queryId].amount)*100*2 );

        players[playerId[_queryId].playerAddress].message = "WIN";
        players[playerId[_queryId].playerAddress].result = randomNumber;

        }
            else{

            players[playerId[_queryId].playerAddress].message = "LOSE";
            players[playerId[_queryId].playerAddress].result = randomNumber;
            }

    waiting[playerId[_queryId].playerAddress] = false;
    }





   function getResult() public view returns(uint amount, uint bet, string memory message, uint result){
        address creator = msg.sender;
        return (players[creator].amount, players[creator].bet, players[creator].message, players[creator].result);
    }

// only owner can set the minimum bet
    function minimumBet(uint minimum) public onlyOwner {
       minBet = minimum;
    }


// only owner can withdraw money
    function withdrawFunds(uint withdraw) public onlyOwner {

       balance = balance - withdraw*100;
       msg.sender.transfer(withdraw*100);
   }

  function insertPlayer(player memory newPlayer) private {
        address creator = msg.sender;
        players[creator] = newPlayer;
        }

}

Hi @Rob_McCourt

Which command are you trying to execute?
Can you post the full screenshot?

1 Like

This was all the result of running npm install truffle-hdwallet-provider.

PS C:\Users\alanm\Documents\code\People> npm install truffle -hdwallet-provider
npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I’ll try to do my best with it!
npm WARN deprecated [email protected]: Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797)
npm WARN deprecated [email protected]: “Please update to latest v2.3 or v2.2”

[email protected] install C:\Users\alanm\Documents\code\People\node_modules\bufferutil
node-gyp-build

[email protected] install C:\Users\alanm\Documents\code\People\node_modules\utf-8-validate
node-gyp-build

websocket@git+ssh://[email protected]/web3-js/WebSocket-Node.git#ef5ea2f41daf4a2113b80c9223df884b4d56c400 install C:\Users\alanm\Documents\code\People\node_modules\web3-providers-ws\node_modules\websocket
(node-gyp rebuild 2> builderror.log) || (exit 0)

C:\Users\alanm\Documents\code\People\node_modules\web3-providers-ws\node_modules\websocket>if not defined npm_config_node_gyp (node “C:\Users\alanm\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\…\node_modules\node-gyp\bin\node-gyp.js” rebuild ) else (node “C:\Users\alanm\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js” rebuild )

[email protected] postinstall C:\Users\alanm\Documents\code\People\node_modules\truffle
node ./scripts/postinstall.js

  • Fetching solc version list from solc-bin. Attempt #1
    npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.1.2 (node_modules\chokidar\node_modules\fsevents):
    npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {“os”:“darwin”,“arch”:“any”} (current: {“os”:“win32”,“arch”:“x64”})
    npm WARN [email protected] No description
    npm WARN [email protected] No repository field.

44 packages are looking for funding
run npm fund for details

found 5 vulnerabilities (1 low, 4 high)
run npm audit fix to fix them, or npm audit for details
PS C:\Users\alanm\Documents\code\People> npm audit fix
npm WARN [email protected] No description
npm WARN [email protected] No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {“os”:“darwin”,“arch”:“any”} (current: {“os”:“win32”,“arch”:“x64”})

up to date in 2.266s

44 packages are looking for funding
run npm fund for details

fixed 0 of 5 vulnerabilities in 472 scanned packages
5 vulnerabilities required manual review and could not be updated

I have read the github post and just wanted to clarify the next step before proceeding.

You are installing the wrong package, run npm i @truffle/hdwallet-provider

kind regards,
Dani

@dan-i

Hello! I was able to proceed further and I have now completed my contract.

It seems to me that the functions works (deposit, withdraw, etc) except for the BET function.

When I interact with the contract setting my bet and my amount I see in the console coming the confirmation till number 24 then it stops and it seems to me I don’t get any random number back.
(I let the page running for 1 hour but no answer).

Could you please help me understand the issue?

this is my contract: https://github.com/enricofabris/COIN_CONTRACT

thanks :slight_smile:

Hi @enrico

I am trying to use your gui but I errors logged as soon as I try to call the function setbet() (in your js function inputData()).

The console shows:

The error suggests to check line 213:

contractInstance.methods.setBet(amount, bet).send({value: web3.utils.toWei(amount, "ether")})

Indeed bet does not seem to be declared.

Check if out and fix it then try again :slight_smile:

Let me know,
Dani

hello :slight_smile:

maybe my page is not clear yet (the interface ahs to be improved), but it works this way.

  1. you input the amount
  2. then you click on 0 or 1 basing on what you want to bet (in this way you define the value of the parameter bet in the setBet function)
  3. click on confirm amount button

In this way I don’t get any error

let me know :slight_smile: thanks