[SOLVED] Casino demo app RPC Error

Hi, I am currently gettings this error. image

process to replicate this error : git clone https://github.com/MoralisWeb3/demo-apps/tree/main/casino-dapp

start ganache
truffle compile
truffle deploy
get the deployed contract address
get the abi
run the front end
login via metamask

I successfully deployed the FlipContract, run the front-end, connect ganache accounts to metamask, I changed nothing but still getting this error

   Deploying 'FlipContract'
   > transaction hash:    0x220c3f3b269effdf44d5973c5f3e0d1e4e745b63f5410e1bb54a68863df32314
   > Blocks: 0            Seconds: 0
   > contract address:    0xbcc2C41574351Dc75801efA100b8Fba4764532D1
   > block number:        94
   > block timestamp:     1633538594
   > account:             0x7Cc4C28876d4F8C7C4A66ba1095D43c85Ee33E60
   > balance:             100.80590688
   > gas used:            708070 (0xacde6)
   > gas price:           20 gwei
   > value sent:          0 ETH
   > total cost:          0.0141614 ETH

   > Saving migration to chain.
   > Saving artifacts
   > Total cost:           0.0141614 ETH

What function/button you click on front end before getting this error?

I input 1 for my bet, click heads then Flip

I find it strange that it looks like the transaction is with a value of 1 BNB instead of 1 WEI.
Do you know how to fund the contract with 10 BNB?
You could do that in the migration file in:

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

module.exports = async function(deployer) {
  await deployer.deploy(FlipContract);
  let instance = await FlipContract.deployed()
  instance.fundContract({value: 100000000000000})

and to use:

  instance.fundContract({value: 10000000000000000000})

Or maybe you can send directly 10 BNB to the smart contract address from MetaMask

it worked now!

I changed the value from 100,000,000,000,000 to 10,000,000,000,000,000,000

I am kinda confused. What happened?

I don’t know exactly what happened in the front end that you ended up sending 1 BNB, but the contract has a check on first line:
require(address(this).balance >= msg.value.mul(2), "The contract hasn't enought funds");
and it will exit if the balance of the contract will not be at least twice the value that you bet, and the initial balance of the contract was less than 1 BNB.

1 Like

Thank you! Great help and suppport