Programming Project - Phase 2

Looks good! One improvement you could make is not displaying the only owner buttons unless the owner is connected to the dapp.

Great idea! I’ll try that.

Programming Project - Phase 2
working with oracles

Hello yet again,

I’ve completed my version of the betting D’app. It successfully works on the Ropsten testnet and communicates with Oracles for randomness. I will be writing tests soon to account for the new betting mechanic. Feel free to look at the source code or clone it and get it working locally for yourself. If you have questions, don’t hesitate to ask!

You can find the source code on my Github => .

Cheers :smiley:

1 Like

I love it! You’re using react, amazing :heart_eyes:

1 Like

Hey @filip I have a small question if you wouldn’t mind lending some advice. I’m trying to revise my d’app after getting halfway through the smart contract security track and realizing my code is super hackable :sweat_smile: lol.

My issue is this

What’s happening is the the Contract’s Balance is actually less than balances[contractAddress] when this bet() function finishes running. – Im assuming there is some sort of cost to run the update() function from within bet() but i’m not sure what to look for to calculate it. Any thoughts?


Hey @rainbows

Their is a price yes, you can get it with the getPrice() :

The return of this function is the price for the request + the gas needed for the callback.

About security you can add a require which check if the balance of the contract is equal to the balances[contractAddress] to make sure you are keeping fees for each update calls you can also add an assert at the end .

I m implementing a mechanism to make the user pay for this request to avoid a gap in the contract balance.


@gabba Hmm, interesting. Im a bit confused though. Since getPrice() takes a string you would need to use it in the actual __callback() since thats the only place a string is used (in this instance). But, thats not actually correct because you want to get the gas price before the callback is even called. Also, the docs also show a “URL” which we aren’t given?

Alsoo, I wouldn’t have getPrice take a bytes32 instead of a string because that would mean we would’ve called the callback to get it. Maybe im overthinking this…

I’d be interested in seeing how you abstract the gas payment to the user.

1 Like

provable_getPrice take a string (datasource) which is an enum, you can use Random in our case.
So you call this function inside the flip function then you subtract the price of the request from the amount the player gonna bet. You will keep the fees for your contract.
it should be 0.004 eth at the moment.

"args": {
			"0": "4000000000000000",
			"price": "4000000000000000",
			"length": 1


Run your provable_newRandomDSQuery() one time before , because the first request is free so it will send you back zero


Explained perfectly, now it works perfectly. You’re a lifesaver :sob: Thanks Gabba!

1 Like

Hello people,

I am unable to use “truffle console” when Ropsten is set as network.
I get:

truffle-config.js has been set as shown in the video.

Am I missing something?

Thanks a lot!

Can you share your truffle-config.js ?
It seems it tries to run truffle in localhost
host ->
port -> 7545

Remove the mnemonicDev and infuraKey before you share it.

You can also look at my previous post in this thread, this truflle config file works.

1 Like

Hi Gabba thanks for your reply.
I’ve checked your config, however I am still not able to connect.

I might be missing my “mnemonicDev”, as I am just using the const mnemonic where my seed is stored.

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

module.exports = {
  networks: {
    development: {
      provider: () =>
        new HDWalletProvider(mnemonic, ""),
        network_id: "*" // Any network (default: none)
    geth: {
      provider: () =>
      new HDWalletProvider(mnemonic, ""),
      network_id: "*"
    ropsten: {
      provider: () => new HDWalletProvider(mnemonic, ``),
      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: {

  mocha: {
    // timeout: 100000

  // Configure your compilers
  compilers: {
    solc: {
       version: "0.5.2",    

! Update !

  • Edited the code above to make it more readable;
  • I don’t get the connection error anymore after changed the config file following your guidelines, now once I write “truffle console” just nothing happens.

Oh i get it it fails when you run truffle console not truffle migrate.
Try to run
truffle console --network ropsten

Edit: When you deploy also use
truffle deploy --network ropsten

Hey Gabba,

I will take some time to get what I am doing wrong. I will update this post once I find the solution

I use @truffle/hdwallet-provider as the other one has been deprecated.

You can try the new package @truffle/hdwallet-provider.

It seems that your error is related to your infuraKey and your .secret file

Hello people,

I was able to connect to ropsten by creating a freshly new folder, pasting the contracts in it and deploying.
Then I added the provable api. sol to the project folder and from that moment on the connection to ropsten is failing again. I am able to deploy all the project that do not have the provable api in it.

Although it does not really makes too much sense to me, I am quite sure that is the issue.

I got the api from here:

Is that link the one you used too?

Took me two days but I am seeing the light at the end of the tunnel :joy:

@dan-i can you share your github repository ?

Here a video for you @gabba
I do show that the contract is deployed in truffle but then fails when import provable api:


1 Like

Yo i opened i pull request on your repo it works now.

The few steps:

rm -rf node_modules
rm -rf build/contracts/

npm install -g
n 11.12.0

truffle version
Truffle v5.1.0-next.1 (core: 5.1.0-next.1)
Solidity - 0.5.12 (solc-js)
Node v11.12.0
Web3.js v1.2.1

I changed you contract name for CoinFlip.sol (before coinFlip.sol) because in your migration you called
const CoinFlip = artifacts.require(“CoinFlip”);
btw i changed it for
const CoinFlip = artifacts.require("./CoinFlip.sol");

I change the compiler version for :

 compilers: {
    solc: {
      version: "0.5.12",    // Fetch exact version from solc-bin (default: truffle's version)

And change the version in all your files. Then

truffle migrate --reset --network ropsten --verbose-rpc
truffle console --network ropsten --verbose-rpc

I also install “web3”: “^1.0.0-beta.34” because i remember that i had issues with the last version.

i maybe have forgotten few things because i was doing something else in the same time.
But if you try my pull request it will works.

Just rm -rf you build/contracts and node_modules before.

Pm me if you still have issues


You were, of course, right. Downgrading the Node to v11.12.0 solved.

For the others, if you need to download node 11.12.0 (

Thanks a lot man :pray:

@filip give a medal to this guy please

1 Like