Programming Project - Phase 2

I’m confused as to why when running on the Javascript VM in remix, whenever I use a function in the contract deployment I will see a green checkmark in the console where I can check the logs but this does not always happen when using injected web3 so even when I see a metamask transaction succeeded notification there will be no green check in the console for me to check the logs for emitted events. Is there a setting for this? An explanation would really help!

I finally finished the coinflipp dapp: https://github.com/rube-de/coinflippDapp
not really pretty, but I learned a lot with events and other solidity specialties
.
coinflippdapp

1 Like

You can see the event by checking the blockchain (etherscan kovan).
https://kovan.etherscan.io/address/0x99e22632FAF3AfA94342137823d68A3aC9c6629E#events

I’m confused as to why when running on the Javascript VM in remix, whenever I use a function in the contract deployment I will see a green checkmark in the console where I can check the logs but this does not always happen when using injected web3 so even when I see a metamask transaction succeeded notification there will be no green check in the console for me to check the logs for emitted events. Is there a setting for this? An explanation would really help!

Not sure what you mean here.

Good job @benr :slight_smile:

Having a difficult time getting my balance to update. I have tried reworking my functions so that I removed an extra step of funding the account but it still won’t add to the balance and then update it based on winning or losing. Could you take a look at my GitHub file link below and give me some help with where I am coding it wrong. Thanks

Link to GitHub Repository

Screen Shot 2021-04-09 at 11.43.50 AM (2)

Hey @cge5009

I would listen for events emitted by your contract, once you get gambleWon or gambleLost you know it’s time to update the balance :slight_smile:
FAQ - How to listen for events

Cheers,
Dani

@dan-i

I have an event listener in and it works. I updated it with my check balance contract instance call but I still don’t get an update. When I try to withdraw balance, the winnings are always zero balance. I am wondering if there is an error with my _payout function but I can’t quite figure out where it would be happing. I know a payable address is required to transfer value but I can’t figure out how to add that into the _payout function or if its needed. Any guidance?

Can you push your updates on github and let me know?

It has been updated and here is the link.

Github link

hey @dan-i

Don’t know what’s the best course of action here. My betting contract is running well in remix using the chainlink oracle, but only when using pragma solidity 0.6.6. When using 0.5.12 (which is the version used in the video and in phase 1 of the project), I receive this error in remix regarding the override keywork in the fulfillRandomness callback function.

Screen Shot 2021-04-13 at 11.14.12 AM

But when I try to simply update my phase 1 betting dapp to 0.6.6, changing the compiler in the truffle-config.js file, and then I try to compile it in truffle again, I get this:
Screen Shot 2021-04-13 at 11.17.02 AM

What should I do? In remix, I’ve tried multiple versions and it seems the oracle only compiles using 0.6.5 and later.

Thanks for the help.

Hi @cge5009

When I try to withdraw balance, the winnings are always zero balance.

You never add balance to mapping (address => account) public accounts; therefore it will always be 0.

Cheers,
Dani

Hi @mervxxgotti

The chainlink oracle version is v6 so just use solidity > 0.6, there is no reason to use 0.5.
About the truffle error, follow this faq and try again: FAQ - How to downgrade Node.Js

Cheers,
Dani

Thanks @dan-i,

I’m still a bit stuck with integrating the contract with the dapp. On remix, since I was using the oracle and the contract on the kovan testnet, do I have to change something in the truffle-config.js? I’m quite lost on where to go next.

Thanks for your help.

I’m simply trying to go line by line with my existing contract to slowly integrate. Adding this line for the chainlink oracle:

import "https://raw.githubusercontent.com/smartcontractkit/chainlink/master/evm-contracts/src/v0.6/VRFConsumerBase.sol";

Receives this error when I try to compile:
Screen Shot 2021-04-14 at 12.26.22 PM

I’m changed my contract and truffle-config file to use solidity 0.6.6;

pragma solidity 0.6.6;

import "https://raw.githubusercontent.com/smartcontractkit/chainlink/master/evm-contracts/src/v0.6/VRFConsumerBase.sol";

contract Betting is VRFConsumerBase {

    uint public balance;
    uint public bet;
    bool public win;

    modifier costs(uint cost){
        require(msg.value >= cost, "Minimum bet or donation is 1 ether!");
        _;
    }

    modifier deploymentCosts(uint deploymentCost){
        require(msg.value >= deploymentCost, "Deployment costs 10 ether to initialize betting pot!");
        _;
    }

    modifier notEmpty() {
        require(balance > 0, "The pot is empty! Must wait for refill or donations!");
        _;
    }

    constructor() public payable deploymentCosts(10 ether) {
        require(msg.value >= 10 ether);

        balance += msg.value;
        win = false;
        bet = 0;
    }

    event betPlaced(uint bet, bool result, uint currentBalance);

    //init pot to 10 ether
    function init() public payable costs(10 ether) {
        require(msg.value >= 10 ether);
        balance += msg.value;
        win = false;
    }

    function placeBet() public payable costs(1 ether) notEmpty returns (uint) {
        //minimum bet is 1 ether
        //require(msg.value >= 1 ether);
        bet = msg.value;
        balance += bet;

        //if random returns 1, user wins, set flag, transfer double of sent bet
        if(random() == 1) {
            require(balance >= bet*2, "Sorry! You won but the contract pot d");

            win = true;
            balance -= bet*2;
            msg.sender.transfer(bet*2);

            emit betPlaced(msg.value, win, balance);

            return 1;

        //if random return 0, user loses, set flag, contract keeps bet
        } else {
            win = false;

            emit betPlaced(msg.value, win, balance);

            return 0;
        }
   }

    function getBalance() public view returns (uint){
        return balance;
    }

    function getSenderAddress() public view returns (address) {
      return msg.sender;
    }

    function getContractAddress() public view returns (address) {
        return address(this);
    }

    function getWin() public view returns (bool) {
      return win;
    }

    function getLastBet() public view returns (uint) {
      return bet;
    }

    function donate() public payable costs(1 ether) {
        balance += msg.value;
    }

    //returns pseudo random 1 or 0
    function random() public view returns (uint) {
        return now % 2;
    }
}

/**
 * Use this file to configure your truffle project. It's seeded with some
 * common settings for different networks and features like migrations,
 * compilation and testing. Uncomment the ones you need or modify
 * them to suit your project as necessary.
 *
 * More information about configuration can be found at:
 *
 * truffleframework.com/docs/advanced/configuration
 *
 * To deploy via Infura you'll need a wallet provider (like @truffle/hdwallet-provider)
 * to sign your transactions before they're sent to a remote public node. Infura accounts
 * are available for free at: infura.io/register.
 *
 * You'll also need a mnemonic - the twelve word phrase the wallet uses to generate
 * public/private key pairs. If you're publishing your code to GitHub make sure you load this
 * phrase from a file you've .gitignored so it doesn't accidentally become public.
 *
 */

// const HDWalletProvider = require('@truffle/hdwallet-provider');
// const infuraKey = "fj4jll3k.....";
//
// const fs = require('fs');
// const mnemonic = fs.readFileSync(".secret").toString().trim();

module.exports = {
  /**
   * Networks define how you connect to your ethereum client and let you set the
   * defaults web3 uses to send transactions. If you don't specify one truffle
   * will spin up a development blockchain for you on port 9545 when you
   * run `develop` or `test`. You can ask a truffle command to use a specific
   * network from the command line, e.g
   *
   * $ truffle test --network <network-name>
   */

  networks: {
    // Useful for testing. The `development` name is special - truffle uses it by default
    // if it's defined here and no other network is specified at the command line.
    // You should run a client (like ganache-cli, geth or parity) in a separate terminal
    // tab if you use this network and you must also set the `host`, `port` and `network_id`
    // options below to some value.
    //
    ganache: {
    host: "127.0.0.1",     // Localhost (default: none)
    port: 7545,            // Standard Ethereum port (default: none)
    network_id: "5777",       // Any network (default: none)
    },

    // Another network with more advanced options...
    // advanced: {
      // port: 8777,             // Custom port
      // network_id: 1342,       // Custom network
      // gas: 8500000,           // Gas sent with each transaction (default: ~6700000)
      // gasPrice: 20000000000,  // 20 gwei (in wei) (default: 100 gwei)
      // from: <address>,        // Account to send txs from (default: accounts[0])
      // websockets: true        // Enable EventEmitter interface for web3 (default: false)
    // },

    // Useful for deploying to a public network.
    // NB: It's important to wrap the provider as a function.
    // ropsten: {
      // provider: () => new HDWalletProvider(mnemonic, `https://ropsten.infura.io/v3/YOUR-PROJECT-ID`),
      // network_id: 3,       // Ropsten's id
      // gas: 5500000,        // Ropsten has a lower block limit than mainnet
      // confirmations: 2,    // # of confs to wait between deployments. (default: 0)
      // timeoutBlocks: 200,  // # of blocks before a deployment times out  (minimum/default: 50)
      // skipDryRun: true     // Skip dry run before migrations? (default: false for public nets )
    // },

    // Useful for private networks
    // private: {
      // provider: () => new HDWalletProvider(mnemonic, `https://network.io`),
      // network_id: 2111,   // This network is yours, in the cloud.
      // production: true    // Treats this network as if it was a public net. (default: false)
    // }
  },

  // Set default mocha options here, use special reporters etc.
  mocha: {
    // timeout: 100000
  },

  // Configure your compilers
  compilers: {
    solc: {
      version: "0.6.6",    // Fetch exact version from solc-bin (default: truffle's version)
      // docker: true,        // Use "0.5.1" you've installed locally with docker (default: false)
      // settings: {          // See the solidity docs for advice about optimization and evmVersion
      //  optimizer: {
      //    enabled: false,
      //    runs: 200
      //  },
      //  evmVersion: "byzantium"
      // }
    }
  }
}

After looking online, I’ve also tried to downgrade truffle to v5.1.65 but then get this compilation failure instead:

Screen Shot 2021-04-14 at 12.41.24 PM

Hi @dan-i,
Thanks for your post about the Chainlink oracle. I’ve been stuck for so long because of provableAPI before realizing that my code wasn’t the issue haha!
I’ve adjusted my contract, everything seems to be working fine: I place my bet, get the random number back, but I can’t call my “checkResult” function automatically from the callback function. I can set the “checkResult” function to “public” and then call it manually, but it’s not very convenient. How could I automatically trigger a function when I get the random number back? Or Am I missing something here?
Also, I’ve tried to define the seed this way to make it dynamic and get a different one with every new bet:
seed = (5446876315487466963158458696 + block.number + now);
But the result is always the same… Is there any way to make it dynamic?

Here is my code so far (deployed on Kovan):

// SPDX-License-Identifier: MIT
pragma solidity 0.6.6;

import "./Ownable.sol";
import "https://raw.githubusercontent.com/smartcontractkit/chainlink/master/evm-contracts/src/v0.6/VRFConsumerBase.sol";


contract CoinFlip is Ownable, VRFConsumerBase {


/* *** Storage ***
===================*/

    uint256 private contractBalance;
    uint256 public randomResult;
    bytes32 internal keyHash;  //For Chailink oracle
    uint256 internal fee;      //For Chailink oracle

    struct Temp {
        bytes32 id;
        uint256 result;
        address playerAddress;
    }

    struct PlayerByAddress {
        uint256 balance;
        uint256 betAmount;
        uint256 betChoice;
        address playerAddress;
        bool betOngoing;
    }

    mapping(address => PlayerByAddress) public playersByAddress; //to check who is the player
    mapping(bytes32 => Temp) public temps; //to check who is the sender of a pending bet


/* *** Events ***
==================*/

    event DepositToContract(address user, uint256 depositAmount, uint256 newBalance);
    event Withdrawal(address player, uint256 amount, uint256 contractBalance );
    event NewIdRequest(address indexed player, bytes32 requestId);
    event GeneratedRandomNumber(bytes32 requestId, uint256 randomNumber);
    event BetResult(address indexed player, bool victory, uint256 amount);


/* *** Constructor ***
=======================*/

    constructor() payable public initCosts(0.2 ether)
        VRFConsumerBase(
            0xdD3782915140c8f3b190B5D67eAc6dc5760C46E9, // VRF Coordinator
            0xa36085F69e2889c224210F603D836748e7dC0088  // LINK Token
        )
    {
        keyHash = 0x6c3699283bda56ad74f6b855546325b68d482e983852a7a82979cc4807b641f4;
        fee = 0.1 * 10 ** 18;
        contractBalance += msg.value;
    }


/* *** Modifiers ***
=====================*/

    modifier initCosts(uint initCost){
        require(msg.value >= initCost, "Contract needs some ETH to initialize the contract balance.");
        _;
    }
    
    modifier betConditions {
        require(msg.value >= 0.001 ether, "Insuffisant amount, please increase your bet!");
        require(msg.value <= getContractBalance()/2, "You can't bet more than half the contract's balance!");
        require(playersByAddress[msg.sender].betOngoing == false, "A bet is already ongoing with this address.");
        _;
    }


/* *** Functions ***
=====================*/

    function bet(uint256 _betChoice) payable public betConditions {
        require(_betChoice == 0 || _betChoice == 1, "The choice must be either 0 or 1");

        uint256 seed = (681717666514 + block.number + block.difficulty);
        playersByAddress[msg.sender].playerAddress = msg.sender;
        playersByAddress[msg.sender].betChoice = _betChoice;
        playersByAddress[msg.sender].betOngoing = true;
        playersByAddress[msg.sender].betAmount = msg.value;
        contractBalance = contractBalance + playersByAddress[msg.sender].betAmount;
        
        bytes32 newRequestId = getRandomNumber(seed);
        temps[newRequestId].playerAddress = msg.sender;
        temps[newRequestId].id = newRequestId;

        emit NewIdRequest(msg.sender, newRequestId);
    }


    function getRandomNumber(uint256 userProvidedSeed) internal returns (bytes32 requestId) {
        require(LINK.balanceOf(address(this)) >= fee, "Not enough LINK - fill contract with faucet");
        
        return requestRandomness(keyHash, fee, userProvidedSeed);
    }
    

    function fulfillRandomness(bytes32 requestId, uint256 randomness) internal override {
        randomResult = randomness%2;
        temps[requestId].result = randomResult;
            
        checkResult(randomResult, requestId);

        emit GeneratedRandomNumber(requestId, randomResult);
    }


    function checkResult(uint256 _randomResult, bytes32 _requestId) public returns (bool) {
        address player = temps[_requestId].playerAddress;
        bool win = false;
        uint256 amountWon;

        if(playersByAddress[player].betChoice == _randomResult) {
            win = true;
            amountWon = playersByAddress[player].betAmount*2;
            playersByAddress[player].balance = playersByAddress[player].balance + amountWon;
            contractBalance = contractBalance - amountWon;
        }

        emit BetResult(player, win, amountWon);

        playersByAddress[player].betAmount = 0;
        playersByAddress[player].betOngoing = false;

        delete(temps[_requestId]);
        
        return win;
    }


    function deposit() public payable {
        require(msg.value > 0);

        contractBalance += msg.value;
        emit DepositToContract(msg.sender, msg.value, contractBalance);
    }


    function getPlayerBalance() public view returns (uint256) {
        return playersByAddress[msg.sender].balance;
    }


    function getContractBalance() public view returns (uint256) {
        return contractBalance;
    }


    function withdrawPlayerBalance() public {
        require(msg.sender != address(0), "This address doesn't exist.");
        require(playersByAddress[msg.sender].balance > 0, "You don't have any fund to withdraw.");
        require(playersByAddress[msg.sender].betOngoing == false, "this address still has an open bet.");

        uint256 amount = playersByAddress[msg.sender].balance;
        msg.sender.transfer(amount);
        delete (playersByAddress[msg.sender]);

        emit Withdrawal(msg.sender, amount, contractBalance);
    }


    function withdrawContractBalance() public onlyOwner {
        payout(msg.sender);
    }

    function payout(address payable to) internal returns (uint256) {
        require(contractBalance != 0, "No funds to withdraw");

        uint256 toTransfer = address(this).balance;
        contractBalance -= toTransfer;
        to.transfer(toTransfer);
        return toTransfer;
    }
}

@mervxxgotti You should be able to get a few hints from my code about how to implement the Chainlink oracle. Just work on remix until your contract is running fine before moving to Truffle/Front-end.
BTW, here are some Chainlink docs:
https://blog.chain.link/random-number-generation-solidity/
https://docs.chain.link/docs/get-a-random-number#config
And the Kovan LINK faucet:
https://kovan.chain.link

1 Like

Thanks man! I’ve got my betting contract with chainlink oracle all good to go in remix but it’s the bringing it over to truffle that has me stuck. I think it has something to do with the solidity version 0.6.6 not working with truffle because I get an error when importing the oracle contract, but when I try to use a higher version like 0.8.0, the oracle only seems to work with 0.6.6? Not quite sure. Screen Shot 2021-04-14 at 12.26.22 PM

I’ve also tried to downgrade my truffle (someone recommended this online) but to no avail.

Screen Shot 2021-04-14 at 12.41.24 PM

Here’s my code as well if you wanna check it out! Just waiting for @dan-i for some assistance :slight_smile:

pragma solidity 0.6.6;

import "https://raw.githubusercontent.com/smartcontractkit/chainlink/master/evm-contracts/src/v0.6/VRFConsumerBase.sol";

contract Betting is VRFConsumerBase {

    uint public contractBalance;

    //for chainlink oracle use
    bytes32 internal keyHash;
    uint256 internal fee;

    uint256 public randomResult;

    struct player {
        address playerAddress;
        uint balance;
        uint bet;
        bool waiting;           //true if player waiting for oracle request
        bool win;               //true if last bet won
        bytes32 requestId;
    }

    struct request {
        bytes32 id;
        address playerAddress;
        uint256 random;
    }

    mapping(address => player) public players;
    mapping(bytes32 => request) public requests;

    event LogPlay(address playerAddress, uint bet, bytes32 requestId);
    event LogGeneratedRandomNumber(bytes32 requestId, uint256 randomNumber);
    event LogGameState(address playerAddress, uint playerBalance, bytes32 requestId, uint256 random, uint contractBalance);
    event LogLinkBalance(uint256 linkBalance);

    /*
     * MODIFIERS
     ************************************************************************************************
     */
    modifier initCosts(uint initCost){
        require(msg.value >= initCost, "Contract needs minimum ether to initialize contract balance.");
        _;
    }

    modifier costs(uint cost){
        require(msg.value >= cost, "Minimum bet or deposit is 1 ether!");
        _;
    }

    modifier ready() {
        require(contractBalance > 0, "Cannot play. Contract balance is empty.");
        require(players[msg.sender].waiting == false, "Cannot play. This player address is already playing and waiting on request.");
        _;
    }

    modifier withdrawable() {
        require(msg.sender != address(0));
        require(players[msg.sender].balance > 0, "This address has no funds to withdraw.");
        require(!players[msg.sender].waiting, "Cannot withdraw while waiting for oracle request.");
        _;
    }

    /**
     * Constructor inherits VRFConsumerBase
     *
     * Network: Kovan
     * Chainlink VRF Coordinator address: 0xdD3782915140c8f3b190B5D67eAc6dc5760C46E9
     * LINK token address:                0xa36085F69e2889c224210F603D836748e7dC0088
     * Key Hash: 0x6c3699283bda56ad74f6b855546325b68d482e983852a7a82979cc4807b641f4
     */
    constructor() public payable initCosts(0.05 ether)   //init costs 50 finney (0.05 ether)
        VRFConsumerBase(
            0xdD3782915140c8f3b190B5D67eAc6dc5760C46E9, // VRF Coordinator
            0xa36085F69e2889c224210F603D836748e7dC0088  // LINK Token
        )
    {
        keyHash = 0x6c3699283bda56ad74f6b855546325b68d482e983852a7a82979cc4807b641f4;
        fee = 0.1 * 10 ** 18; // 0.1 LINK

        contractBalance += msg.value;

        players[msg.sender].playerAddress = msg.sender;
        players[msg.sender].balance = 0;
        players[msg.sender].bet = 0;
        players[msg.sender].waiting = false;
        players[msg.sender].win = false;
        players[msg.sender].requestId = 0;

        emit LogGameState(players[msg.sender].playerAddress, players[msg.sender].balance, 0, 0, contractBalance);
    }

    function play() public payable costs(0.01 ether) ready {
        players[msg.sender].playerAddress = msg.sender;
        players[msg.sender].bet = msg.value;
        players[msg.sender].waiting = true;

        bytes32 newRequestId = getRandomNumber(0);

        players[msg.sender].requestId = newRequestId;

        requests[newRequestId].id = newRequestId;
        requests[newRequestId].playerAddress = msg.sender;

        emit LogPlay(players[msg.sender].playerAddress, players[msg.sender].bet, newRequestId);
    }

    function updateGame(bytes32 requestId) public {
        address playerAddress = requests[requestId].playerAddress;

        requests[requestId].random = randomResult;

        if(requests[requestId].random % 2 == 1) {
            players[playerAddress].win = true;
        } else {
            players[playerAddress].win = false;
        }

        updateBalances(playerAddress, requestId);

        players[playerAddress].bet = 0;
        players[playerAddress].waiting = false;

        //delete(requests[requestId]);
    }

    function updateBalances(address playerAddress, bytes32 requestId) public {
        if(players[playerAddress].win) {
            players[playerAddress].balance += players[playerAddress].bet * 2;
            contractBalance -= players[playerAddress].bet * 2;
        } else {
            contractBalance += players[playerAddress].bet;
        }

        emit LogGameState(
            playerAddress,
            players[playerAddress].balance,
            requestId,
            requests[requestId].random,
            contractBalance
        );
    }

    function logGameState() public {
        emit LogGameState(
            msg.sender,
            players[msg.sender].balance,
            players[msg.sender].requestId,
            requests[players[msg.sender].requestId].random,
            contractBalance
            );
    }

    function withdrawPlayerBalance() public withdrawable {
        uint amount = players[msg.sender].balance;
        delete(players[msg.sender]);
        msg.sender.transfer(amount);

        emit LogGameState(
            msg.sender,
            players[msg.sender].balance,
            players[msg.sender].requestId,
            requests[players[msg.sender].requestId].random,
            contractBalance
        );
    }

    function withdrawContractBalance() public {
        uint256 amount = contractBalance;
        contractBalance = 0;
        msg.sender.transfer(amount);

        emit LogGameState(
            msg.sender,
            players[msg.sender].balance,
            players[msg.sender].requestId,
            requests[players[msg.sender].requestId].random,
            contractBalance
        );
    }

    function deposit() public payable costs(1 ether){
        contractBalance += msg.value;
        emit LogGameState(
            msg.sender,
            players[msg.sender].balance,
            players[msg.sender].requestId,
            requests[players[msg.sender].requestId].random,
            contractBalance
        );
    }

    /**
     * Requests randomness from a user-provided seed
     ************************************************************************************
     *                                    STOP!                                         *
     *         THIS FUNCTION WILL FAIL IF THIS CONTRACT DOES NOT OWN LINK               *
     *         ----------------------------------------------------------               *
     *         Learn how to obtain testnet LINK and fund this contract:                 *
     *         ------- https://docs.chain.link/docs/acquire-link --------               *
     *         ---- https://docs.chain.link/docs/fund-your-contract -----               *
     *                                                                                  *
     ************************************************************************************/
    function getRandomNumber(uint256 userProvidedSeed) public returns (bytes32 requestId) {
        require(LINK.balanceOf(address(this)) >= fee, "Not enough LINK - fill contract with faucet");
        return requestRandomness(keyHash, fee, userProvidedSeed);
    }

    /**
     * Callback function used by VRF Coordinator
     */
    function fulfillRandomness(bytes32 requestId, uint256 randomness) internal override {
        randomResult = randomness;

        requests[requestId].random = randomResult;

        updateGame(requestId);

        emit LogGeneratedRandomNumber(requestId, randomResult);
    }

    /**
     * Withdraw LINK from this contract
     *
     * DO NOT USE THIS IN PRODUCTION AS IT CAN BE CALLED BY ANY ADDRESS.
     * THIS IS PURELY FOR EXAMPLE PURPOSES.
     */
    function withdrawLink() external {
        require(LINK.transfer(msg.sender, LINK.balanceOf(address(this))), "Unable to transfer");
    }

    function getLinkBalance() public view returns (uint) {
        return LINK.balanceOf(address(this));
    }

    function emitLinkBalance() public {
        emit LogLinkBalance(LINK.balanceOf(address(this)));
    }

    /**
    * GETTERS
    * *********************************************************************************
    */

     function getThisPlayer() public view returns (address playerAddress, uint balance, uint bet, bool waiting, bool win, bytes32 requestId, uint256 random) {

        return (players[msg.sender].playerAddress,
                players[msg.sender].balance,
                players[msg.sender].bet,
                players[msg.sender].waiting,
                players[msg.sender].win,
                players[msg.sender].requestId,
                requests[players[msg.sender].requestId].random
                );
    }

    function emitThisPlayer() public {
        emit LogGameState(
            msg.sender,
            players[msg.sender].balance,
            players[msg.sender].requestId,
            requests[players[msg.sender].requestId].random,
            contractBalance
        );
    }

    function getPlayer(address _address) public returns (address playerAddress, uint balance, uint bet, bool waiting, bool win, bytes32 requestId, uint256 random) {
        require(_address != address(0x0), "Player with this address does not exist.");

        emit LogGameState(
            msg.sender,
            players[msg.sender].balance,
            players[msg.sender].requestId,
            requests[players[msg.sender].requestId].random,
            contractBalance
        );

        return (players[_address].playerAddress,
                players[_address].balance,
                players[_address].bet,
                players[_address].waiting,
                players[_address].win,
                players[_address].requestId,
                requests[players[msg.sender].requestId].random
        );
    }

    function getThisPlayerBalance() public view returns (uint) {
        return players[msg.sender].balance;
    }

    function getPlayerBalance(address _address) public view returns (uint) {
        return players[_address].balance;
    }

    function getContractBalance() public view returns (uint){
        return contractBalance;
    }

    function getContractAddress() public view returns (address) {
        return address(this);
    }

    function getSenderAddress() public view returns (address) {
        return msg.sender;
    }
}

1 Like

Awesome, thanks! Seems like I had a variable scope issue… All good now. Sucks being a beginner haha, spending hours/days trying to figure out simple stuff!

Can’t really help about your truffle issue, but I’m sure someone will :slight_smile:

1 Like

Hi @mervxxgotti

import "https://raw.githubusercontent.com/smartcontractkit/chainlink/master/evm-contracts/src/v0.6/VRFConsumerBase.sol";

You cannot import that way if you want to compile with truffle.

In order to import contracts using Truffle, these contracts have to be in your local machine.

You can either npm init your project and npm i @chainlink/contracts then import the contract you need from node_modules, of manually copy the contracts you need and paste them in your project to import them.

For provable api Filip uses the 2nd method: https://academy.ivanontech.com/products/old-ethereum-smart-contract-programming-201/categories/2004134/posts/6702339

Cheers,
Dani

2 Likes

Let me know if you need help :slight_smile:

1 Like