Programming Project - Phase 2

Yo
This is my Programming Project phase 2.

You can create a bank using an oracle or a simple bank using a pseudo random function based on blocktime and block difficulty as it can be exploit by a miner the amount to bet for this one is 5 eth.

The simple bank is really faster and cheaper but less secure :man_shrugging:

Live version here:
https://mysterious-lowlands-26449.herokuapp.com/

(Refresh the page when you see the heroku error i didn’t check yet what is the real problem with heroku)

github repo:

Waiting for your feedback :slight_smile:

2 Likes

Hi Filip @filip,

I have the same problem installing hdwallet-provider even though I downgraded npm version to 6.4.1:

Hi @Karolis_Abramavicius,
I have the same problem, did you manage to solve it?
Thanks.

Hi @Golden_Pig_Coin

This issue is caused by your node version, not only the npm one

Try with the version:
https://nodejs.org/download/release/v0.11.15/node-v0.11.15-x86.msi

Or you can use nvm to switch node version:

1 Like

Hi @gabba
thank you for your reply!
I installed the nvm and installed both versions of NodeJS 10.18.0 and 0.11.15.


However, I was only able to install truffle under 10.18.0 but not under 0.11.15. When I try to install truffle under 0.11.5, the above error occurs.
So I still cannot install the hdwallet.

@filip @gabba
I managed to solve the problem. Thank you!

To whom also have the problem when installing truffle hdwallet-provider, first, make sure that you have installed Git before you start.
Link for installing Git I used is:
https://gitforwindows.org/
Then follow the instructions from the following link:

the new command is:

npm install @truffle/hdwallet-provider
2 Likes

Dear Academy Community Members,
I thought after all the effort, I finally managed to install hdwallet-provider, but when I try to run the command truffle migrate --network ropsten, it still says that cannnot find module ‘truffle-hdware-provider’, anyone knows how I can solve it?
Thank you in advance!

Can you share your package.json file ?

yes, here it is:

{
  "name": "peopleproject",
  "version": "1.0.0",
  "description": "",
  "main": "truffle-config.js",
  "directories": {
    "test": "test"
  },
  "dependencies": {
    "@truffle/hdwallet-provider": "^1.0.30",
    "core-js": "^3.6.4",
    "truffle-assertions": "^0.9.2"
  },
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

You need to change the library you are calling in truffle-config.js
I guess you are still calling the old version of truffle wallet.
Try this one instead.

const HDWalletProvider = require('@truffle/hdwallet-provider');

You can have a look at the basic config file in their repository at the end.

Edit: i gave you a link to the old lib eheh

This one is better :wink:

1 Like

You are right!
I can’t thank you enough!

You just made my day by helping me solving two problems!
Now I can finally start with my own project!

Hey @filip and @gabba,
I really enjoied waking through the lessons! :grinning:

I changed the exercise of a FlipCoin to Throwing a Dice. The process is the same, except of some if-else statements to treat the possible solutions.

The Program works, but if you win, you don´t get money the potential win from the contract to your address.

Could you please take a look? The dapp isn´t finished, but the contract should be.

my code: https://github.com/MariusWesten/ThrowDice/blob/master/contracts/Bet.sol

Hi @Mamo_West

It s a good idea to try to make a different Dapp :slight_smile:
Few comment on the contract:

If you want to check the provable address in the callback you need to set

provable_setProof(proofType_Ledger);

In the constructor otherwise the callback will fail.

I don’t think you need to call update() a first time in the constructor because you will loose your free call.
It’s a good idea to create a self destruct function to get back your fund when you want to destroy the contract. But you don’t have to transfert the fund before the selfdestruct function is called, because it takes a msg.sender as argument and it sends back the fund from the contract to the address specify.
So you can just do

function close() public onlyOwner {
        selfdestruct(msg.sender);
    }

In your throwDiceResult you cannot divide floating number, actually their is no floating number in solidity, you will have to deal with wei , or assign a number of ether to a variable the (0.5 ether) you can find in the documentation is just a syntax sugar to avoid typing everything in wei. Does it work for you in remix ?

Your throwDice function is payable but the player is not able to multiply his gain because you are not using this value later. So for now if i bet 0.5 eth or 2 eth the gain will be the same ? Even you use this Dapp with a web3js interface someone is still able to interact with it directly on the blockchain.

Did you try your contract on Remix because i think the contract can compile but can’t execute. It’s probably cause by the contract size.

You are doing a nice usage of private, strongly typing variable and function is a good practice and can help you to limit the size of you contract.

Do not hesitate to post a video of your Dapp when it’s done :slight_smile:

Edit typo

2 Likes

Tank you @gabba for your help! :heart_eyes:
I try to finish the project until tomorrow to show some results!
You really know how to explain !

2 Likes

Here is mine!

The video il long due to the oracle time :slight_smile:

GitHub:

2 Likes

Hi @dan-i great job :+1:
I looked at your contract and your video it seems to work great well done but i wasn’t able to deploy it on remix. Doest it work for you on remix ? I got the gas issue error.
I like the idea of doing the *2 in the withdraw function instead of inside the verifyResult to save gas.
Few security advise:

  • verifyResult shouldn’t be public because i can call it with my own random number before the call back is executed and win a lot of money :wink:
  • You should check the provable_newRandomDSQuery price because the balance of your contract will not be correct. (see the converstation with “rainbows” above )
2 Likes

Hey Gabba thanks for taking the time to look into my project man :slight_smile:

Is is most likely related to the fact that the callback function does not work anymore (no idea why).
Basically you send money with flip () but wait endlessly for a callback from the oracle that never comes.

I have to look into it, never ever had issues with the oracle

@gabba

They have fixed the oracle :slight_smile: works again now.
Also your contract got the callbacks for the transactions we sent yesterday (after 4h though).

My contract also works again today

1 Like

This is really weird, i ll not trust this oracle for an app in production…

2 Likes

Hey everyone,

I am starting phase two tonight and read through the thread to see what issues everyone was hitting. I noticed that most advice was to downgrade Node, NPM, Truffle and SOLC.

First why is this necessary?

Second what are the suggested versions or each?

Thank you in advance.