Programming Project - Phase 2

@dan-i
thanks, but this was working already against my local ganache. (its actually ropsten I was having problems with).

btw getMyBalance() was already working too without an explicit address parameter and instead using the implicit msg.sender that it receives

Just a quick heads up for all of you. When you make the .secret file make sure you git ignore it or your gonna get rekt… just like me lol. Remember that UNI airdrop? Me too, I had 400 tokens for about 5 seconds and then… REKT CITY. All because of this:

Sorry to hear about this sir, :frowning: indeed you should always be careful with your private keys.

Carlos Z.

Guys I am so paranoid about this. how do I git ignore the right way?

Hi @elterremoto

There is a really good tutorial from GitHub that I suggest you to read: https://docs.github.com/en/github/using-git/ignoring-files

Create a new repo and test it until you get confident enough.

Happy leaning,
Dani

1 Like

I know this is a stupid question… but here it goes. If I create my smart contract on the test network people can’t see the .secret file correct?

1 Like

@Taha @filip
Hey everyone,

I’ve been really struggling to get this part of the project completed. every time i thought i made some headway i would find another issue thats made me feel like i needed to startover again … i’ve finally spent a lot of time troubleshooting and adjusting and this is currently where i’m at. I would greatly appreciate some guidance to iron out the last few kinks.

github link

Contract is deployed on ropsten testnet.
My oracle call works and a random number is generated and that generatedrandomnumber event is emitted and logged to the console.

For some reason the flipcoinresult event is not emitting/ I cant seem to get it to log to the console. I’ve spent a good few hours trying to troubleshoot this with no luck.

I get an error when trying to check user balance that it is not a function, but i saw @dan-i’s reply to emmet, and mine looks identical so not sure why this isnt working and im not sure how to troubleshoot.

I’m still going to continue trying to widdle away at resolving these errors on my own, but some tips/guidance would be so helpful to me. This phase of the project has taken me weeks to get this far and i really want to learn what im doing wrong or if im going about certain operations in the wrong way.

thanks in advance for any assistance

-Cody

Id like to know the answer to this as well. I believe it is a no, but would like to get someone with the knowledge and experience to answer definitively as my intention was not to create a gitignore file, but instead to just not upload that file at all (I am manually uploading each of the files to my github account) - I don’t see any need for it to be shared as surely someone else can just deploy the contract from their own wallet with their own .secret file if they want to see my contracts in action…? If I am mistaken, please advise…cheers

Hi @elterremoto

It is not possible to see your .secret file by looking at the your contract via etherscan.

Cheers,
Dani

1 Like

Hey @CodyM

I like that you tried to look for the solution yourself. It is really important to struggle in order to really learn how to do stuff :slight_smile: kudos here!

You are not handling the events correctly in your main.js. I fixed GeneratedRandomNumber, look at what I did and fix the other ones yourself.

My test: https://ropsten.etherscan.io/address/0x41626e0410cfE44bf5Fa3913c738bd9491887EEA

    contractInstance.events.GeneratedRandomNumber(function (error,result){

        //prints a 0 or 1 to console showing chosen rnadom number
        console.log('I catched this event :) the returned value is: ' + ' ' + result.returnValues.randomNumber);
    })

As you see above, I am looking at result.returnValues.randomNumber.
In order for you to understand why, try to console.log(result) and look into it :wink:

This is the result:

Cheers,
Dani

2 Likes

@dan-i
thank you so much for the thoughtful response and I appreciate you looking at my code!

I’m going to go through your comments and continue troubleshooting and revising the code - hopefully will be back later today or tomorrow with a completed project!

thanks again!

-Cody

1 Like

Finally … here is my completed project. Thanks again for the tips @dan-i!!

Github Link

Fully functional on ropsten testnet :slight_smile:

1 Like

Hey @CodyM

Really proud to see the improvement here :slight_smile:
Two challenges for you:

  • function __callback(bytes32 _queryId, string memory _result, bytes memory _proof) try to use the param @_ proof.

  • Every time (except the 1st one) that you call the function provable_newRandomDSQuery your contract does pay money. Find out what this amount is and deduct it from the user’s bet (so that the user will pay for the oracle call).

Both this info are in the provable API documentation.
You might search into this forum too since I have left some posts with these info.

Try to read the docs first as this is really important as a dev.

Good luck,
Dani

2 Likes

To make sure I got the environment set right, I tried to deploy my existing contract on Ropsten. To remove the pseudo randomness, I set the function to always return 1.

When installing @truffle/hdwallet-provider, I get these:

And when trying to deploy, this:

image

Hey @MarcisB

The ones on the first screenshots are usual warnings.
Try truffle migrate --reset --network ropsten then truffle console --network ropsten

Happy coding,
Dani

2 Likes

Thanks, that worked!
Next, I ran into this:

image
So I removed one zero from the gas setting in truffle-config.js, but what exactly does this number define? Is that amount of gas sent at the beginning, and then I get back the unused…?

Ok, this is doing my head in, I can’t seem to solve this issue, can someone please help.

I keep getting the following when I try to listen for events in my JS file…
Uncaught TypeError: Cannot read property ā€˜events’ of undefined

I can see that the events are logged in my console when I call the functions and I have tested my dApp thoroughly. I just keep getting the same thing in my console when I load the page, it doesn’t matter which event I try to listen for, they all say the same thing. I am clearly missing something…

Makes no sense to me as I have tried so many different variations of the code to no avail. I’ve been trying to problem solve this for quite a few hours over the last few nights and do not understand why it is telling my this. The following is the simplest piece of code I have used, I have removed everything I feel is unnecessary in order to reduce the likelihood of mistakes and am calling it for the event that is created when the user places a bet, just to get it to work (as I can see this one logged in my console as part of the contract transaction…I am not trying to listen for the callback event at this stage (as I read in a post above that there was issues with Ropsten and the callback event listener or something).

    contractInstance.events.BetPlaced({
        fromBlock: 0
    }, function(error, event){console.log(event);})
    .on('data', function(event){
        console.log(event);
    })
    .on('error', function(error, receipt) {
                console.log(error);
                console.log(receipt);
    });

Please advise what it is that I am obviously missing/misunderstanding…

Edit: (Oct 4th)
@Taha @dan-i - I am at a stand still with this and would like to move on - I’ve spent time every night trying to understand why this isn’t working - I can see the events having been logged in my console after I send transactions to the contract from my front end using contractInstance.methods.enterFunctionHere() but trying to listen to events with contractInstance.events.EnterEventHere(......) is resulting in an error stating events undefined or something. Please advise, I would like to move on but can’t solve this, cheers

Edit: (Oct. 7th)
I have now solved the problem. I will hopefully be sharing my completed project within the next day or so.

I am getting the same error when trying to redeploy my contract on Ropsten. First the error message ā€œexceeded the block limitā€¦ā€ And when I lower the gas limit the TX runs out of gas or gives an error saying From is null…(??) Is there something wrong with ropsten?

1 Like

Now that I tried to implement oracle, I also ran into this:

image
What would be adequate gas?

1 Like
1 Like