Programming Project - Phase 2

The issue I’m having is that changes I’m making in the main.js file is not being reflected. I’m not exactly sure what the issue is but I’m thinking it is a deployment issue. I’ve tried redeploying the contract on Ropsten but no luck. Can you see if you are able to run my project and see if you have similar results?

Hey @dan-i, I got the hdwallet-provider to install, but now when I try to migrate to Ropsten I’m getting an error that the link to the provablethings API can’t be found. I tried the different versions (0.5, 0.6, etc) from the Github page with “https”, and I tried them without “https” because that’s how it was formatted on docs.provable.xyz, but it still can’t be found. Any advice? Thank you

yes i changed it. and I had the same error.
the strange thing was that i received this,when i installed npm install @truffle/hdwallet-provider


i solved this with npm install -g npm-install-peers but does not work either.

the other thing is this
image
i don’t know what to do here :smile:, sorry maybe is a small thing, but i could not find it.

Are you migrating with Truffle or Remix?
Share your contract.

Cheers,
Dani

I’m having trouble deploying my contract to the Ropsten test network. I’ve found a couple of other people in this forum with this problem, but no solution yet.

Things I’ve checked so far:

  • Network config in my truffle-config.js
  • Balance in the account (filled through faucet.ropsten.be)
  • In metamask I have Ropsten selected as network
  • Double checked my mnemonic

I do have multiple addresses in my metamask though, so I wonder how I can select which one should be used for deploy? To be sure I added funds to all wallets through the faucet, so any wallet used from metamask should be sufficient…

The cli command I use for deployment:

truffle migrate --reset --network ropsten

The error in cli:

Error:  *** Deployment Failed ***

"Migrations" -- insufficient funds for gas * price + value.

    at /Users/seer/.config/yarn/global/node_modules/truffle/build/webpack:/packages/deployer/src/deployment.js:365:1
    at process._tickCallback (internal/process/next_tick.js:68:7)
Truffle v5.1.59 (core: 5.1.59)
Node v10.23.0

My project code can be found here: https://github.com/ChristianVermeulen/Coinflip


Edit: I tried adding from: '0x... to my network config to force the correct address from my wallet. This results in:

"Migrations" -- Unknown address - unable to sign transaction for this address: "0x....".

What am I missing here? :thinking:


Edit 2: This keeps getting weirder… So I tried to verify my wallets through MyEtherWallet by uploading my Mnemonic key there and see to which accounts I have access. These do not match the accounts in my metamask… What is going on here?

@dan-i I’m using Truffle.
Sure, https://github.com/MBurtonshaw/dapp_project/tree/main/1

This is my take on the DApp. There are still some improvements to be done (like adding an event listener, handling of multiple provables).
This is the first shot to start to improve on.
GitHub: https://github.com/rkindle/Coinflip
Pictures:

hi @dan-i I restarted my computer and switched to git bash which seemed to work. However, I’m still seeing what I thought was an error related to deployment when running the app. Any advice here?

Hello @filip and @dan-i, i finally come up with a working version of Dapp which is the closest i could do without asking you for hints with the following 3 problems, which i couldn’t resolve myself researching online.
Here is my code https://github.com/p4perclip/CoinFinal/tree/main/Final

Here is link to video:https://www.dropbox.com/s/o58js2c4tt5fmmc/simplescreenrecorder-2020-12-31_18.34.45.mp4?dl=0

  1. The ‘withdraw all’ function is passing tests but it is not possible to withdraw the balance.
    Most of the time i will get back the following error:
    ALERT: Transaction Error. Exception thrown in contract code.
    error Withdrawall
  2. I couldn’t find a way to test my bet function properly and the events associated with it. I was getting back ‘big number’ errors etc. I tested a couple of library’s but i still cant find a solution.
  3. In my main.js file when passing the events after withdrawal as a player or owner i got a ‘Big number’ error too. I tried to add the ethers library which i used on the tests but i got back a ‘require’ error.

My Improvements based on my previously posted project:

https://github.com/CatalystJesal/CoinFlip/tree/react-redux

My experiences and issues

I spent quite a lot of time to try and improve the application. I decided to use React for the front-end and learnt how to use Redux to preserve some parts of the state within my application. Actually, I spent a lot of time mostly trying to display “minutes ago” using Moment.js library for the recent winners you would see on the left-hand side of the application.

I ran into issues trying to re-render the component to show those timestamps, it would show default 0 values and unfortunately I decided to disbanded that code since I got nowhere with trying to get actual timestamps to show. It was why I had intended to use Redux to see if there was anyway to re-render the timestamps to show when the recent winners bets were made.

It took me a whole week to no avail trying many different things I could think of. At least I got to learn how Redux works on the bright side.

Would appreciate if someone can enlighten me on how to get an async function call which awaits for the timestamps to be gathered for each recently winning bet to be rendered successfully as soon as the page loads and once a successful bet outcome has been propagated via the event to blockchain. I have no code to show what I had done from before as I had gotten rid of what I had.

Thanks

Insufficient funds issue solution!

Problem: When trying to deploy to Ropsten you get "Migrations" -- insufficient funds for gas * price + value..

Solution: In my case, the metamaskt passphrase would not resolve to the accounts in metamask. Instead of using the metamask passphrase, you can also use the private key of a specific account (the one funded through the faucet). Then, only that account will be available and thus used by deployer.

private

More information on stackexchange: https://ethereum.stackexchange.com/questions/68184/truffle-tries-deploy-from-unknown-account

Bonus: Here is how to log available accounts during deploy:

// 1_initial_migration.js
const Migrations = artifacts.require("Migrations");

module.exports = function(deployer, network, accounts) {
  console.log(network);
  console.log(accounts);
  deployer.deploy(Migrations);
};
2 Likes

So I revisited the Coin Flip project and integrated the Chainlink random number generator. Unlike the Provable API it actually returns a response every time! :laughing:

The project was done in Angular 8 with some bootstrap. I resisted the urge to re-write the UI in React. The UX could be better but it works!

Hosted on Netlify here:
https://mayjer-cryptocoinflip.netlify.app/

Github repo:
https://github.com/jermay/CryptoCoinFlip

Cheers.

1 Like

From your screenshot we can see that the transaction was reverted. This is most likely due to a require statement in your contract that is failing.
Double check the function you are calling and verify that the requirements are satisfied.

Hey @Lukasz

Are you calling withdrawUserBalance or withdrawAll?

The error you are facing is most likely related to a require statement that does no pass.
Double check the require statements in the two functions mentioned above (withdrawAll has an onlyOwner modifier attached to it).

Also you can add a message in your require, so that when the function fails you will be able to see why.

example:

 function withdrawUserBalance() public returns (uint256){
    require(playInfo[msg.sender].inGame == false,'player still in game');

Then you can call your function, confirm the transaction, and check the error message once it fails.

Hey @Jian_Hao_Wei

I am checking you dapp.

contractInstance.methods.owner().call().then(function(owner){
        if (owner.toLowerCase() == from.toLowerCase()) {

from is not defined, double check that if statement.
You have a var from but it is not assgined.

It seems that I am able to use your event.once.

1st game

2nd game

1 Like

Hi @dan-i,

Thanks for your time to look at my problem.

The variable from is defined in my code see screenshot below.

A question in which block number was the callback of your 1st game?
The bug only occurs if the blocknumber of the callback of the 1st game is higher than the blocknumber of 2nd game.

The bug only occurs in the following scenario:
Block 1: Start game 1
Block 2: Start game 2
Block 3: Oracle callback of game 1. This triggers the event.once of game 1 and game 2.
Block 4: Oracle callback of game 2. Nothing happens

Hey @Jian_Hao_Wei

I modifiedyour code couple of days ago and I removed from = accounts[0].
Apologies my bad, I totally forgot it.

I just retried and I can confirm that I only see the right betResult event and it is not repeated twice.
As in my previous screenshots I see only the event related to the right queryId

Below a screenshot of my whole console so that you can verify.

Can you double check and retry?

Please keep me posted,
Dani

Hey @dan-i,

It is very strange that we get different results.
I ran my code again and it got the following results below.
One callback stills triggers both events.

Can you try to play 2nd game immediately after approving the first game in metamask before the 1st game is being mined? If we still get different result that it must some bug in the JavaScript.

KInds regards,

Jian

Hello @dan-i checked my code again and indeed in my WithdrawUserBalance function assert statement was a culprit which didn’t allowed to WithdrawAll function to work ,now everything works fine, . Here is fixed version of my Dapp https://github.com/p4perclip/CoinFinal/tree/main/Final
Please review my code, to be sure everything is alright.

1 Like

Hi @filip and @dan-i,

I finally managed to develop a version of my CoinFlip DApp that runs on Ropsten testnet and uses the Provable oracle for real randomness. It took quite a while to solve all the problems, but I 've learned a lot on the way.

My code has been published here: https://github.com/laurenzius-dlt/coinflip-2v0

A demo video of the CoinFlip 2v0 is avaiable here: https://vimeo.com/496485891

I think there is still a lot to improve. Here are some ideas for future versions:

  1. make the code less verbose and reduce redundancy (since the first focus was only learning and better readability)
  2. find a better solution for the problem to avoid catching the same event multiple times (which I solved at first place by a hack using an event sequence number)
  3. (after finishing the course “Ethereum Smart Contract Security”)

I want to say thanks to @filip and the IoT team for this course. I really like the good presentation on one hand and the project-based style of learning on the other hand.

Any feedback is welcome!

1 Like