Programming Project - Phase 1

@filip I have finished the phase one project. I also liked the format of this project and learned a lot. I did hit a few changes that were frustrating. Like some others above from time to time an RPC error is thrown though sometimes the transaction still completes. Did anyone find a repeatable cause for this issue? I also ran into an issue where a transaction got stuck and nothing worked until I reset the accounts in MetaMask.

I am really enjoying this course - thank you!

Project Repository

1 Like

Hi,
in the withdrawal function, I used the same structure which was used in the people.sol (checks effects interaction pattern) in order to eliminate re- entrency fallback risks as follows:

function withdrawAll() public onlyOwner returns(uint) {
uint toTransfer = acountBalance;
acountBalance = 0;
msg.sender.transfer(toTransfer);
return toTransfer;

However, it is not clear to me

  • why do we need to return (the last line)?
  • Is it really necessary to keep the checks effects interact pattern? (as transfer() should be safe against re-entrancy anyway)?

Thanks

The return will only be needed if you want to check the value in remix or in your frontend it’s not really needed.
There was a debate not long ago about saying the transfert function was not safe in case the gas cost of other op code change. So it’s an additional precaution.
This is an interesting post about it.

(The title is a bit a Clickbait don’t worry about transfert for what we are doing :slight_smile: )
https://diligence.consensys.net/blog/2019/09/stop-using-soliditys-transfer-now/

Woo really nice implementation :+1:
Using a storage contract is a good idea !
Even the proxy feature is great, well done.
Just by curiosity what is your programming background @xactant ?

@gabba Thank you! I have been a profession software engineer since 1997 but started as a hobbiest in highschool in 1984. Currently I am a Java Dev Lead for the company I am currently with. My experience is mainly Enterprise systems integration but I have also done a good share of Web UI (js, angular, etc) and hardware device drivers (mainly blue tooth). Trying to break into defi now.

How about you?

I have definitely less skin in the game than you ahah i m coding since 2014 i started with C. Currently software engineer too i m working on a C network library since 2 years, but i had C++ , reactjs and rails experience before.

I m also interested into Defi, we have a project to implement a smart contract in top of compound right now with few students if you want to share knowledge have a look at this post from Bam:

1 Like

Submitting my phase 1 project.

Below is the download link of my files:
https://we.tl/t-qTPq9tVoGh

Need to say, that implementing process that requires simultaneous writing functions in solidity and testing them with truffle was the biggest thing I learned in this course so far, It makes development quicker and much more secure.

During the development of this project, I had a problem when calling transactions using metamask (rpc error with payload), At first, I used accounts[0] (owner address), and it was throwing this error time to time. After I sit on this project day later, every transaction was failed. After switching to another account, I managed to get it running again with errors throwing back from time to time. Did anyone had this issue? Any ideas on how to fix it? When using truffle, never had errors, and transactions were always out.

2 Likes

Phase 1 complete https://drive.google.com/open?id=1E5xUMbFLIAV2pOBIDgLmIO7htDCjPBKz
just a note that the metamask dialog doesn’t show up in my recording but is present.

1 Like
1 Like

Hi everyone! I finished Phase 1, but I couldn’t get my dapp listening to the bet Solidity event, so I can display a box saying You won 2*betAmout or you lost your betAmount. @filip , how is this done, I only found outdated documentation and an old video of yours from 2018 on this. Here is the link.

Hi @Dominik_Clemente
I just checked your project it could be nice to implement the other functions of your smart contract in your web application. Because as you are not sending fund when the contract is deployed i had to send eth via truffle console. Even for getBalance it could be useful for the player to check if they have something to win by playing :slight_smile:

For your event you can catch it this way

async function bet(){
    var betAmount = $("#name_input").val();

    var config = {
        value: web3.utils.toWei(betAmount.toString(), "ether"),
        gas: 100000
    }
    try {
    let res = await contractInstance.methods.flip().send(config);
        try{
            await contractInstance.getPastEvents(['bet'], {fromBlock: 'latest', toBlock: 'latest'},
            async (err, events) => {
                console.log(events[0].returnValues);
            });            
        }catch(err){
        console.log(err)
        }
    }catch(err){
        console.log(err)
    }
}

It seems their is an issue with the last version of ganache Gui it doesn’t work for me too i can’t get the event. But i got them using ganache-cli so if you have any issues with this code try to run ganache-cli.

1 Like

Hi @gabba, I tried your recommendation, however when I switch to ganache-cli and send the transaction I get a MetaMask error MetaMask - RPC Error: Error: [ethjs-rpc] rpc error with payload {"id":9541774025292,"jsonrpc":"2.0","params":["0xf877808504a817c800830186a094d2ac41e712f94f1b3484c04568ac47d3304a85618829a2241af62c000084cde4efa98602e1b4904f8ba0461575789f079b1385b7e8bd8616f7917d6b1006d8869049d704287477426023a028746270940a9d0dc0fcf64b9abafde8af2745df5ddc28e2e3884ff5e9cf9cb1"],"method":"eth_sendRawTransaction"} [object Object]

I did check and corrected the abi and the deployment address, however it still had the same error. How can I fix it? Thanks for your help

Hi again :slight_smile:
Check the port on metamask because ganache-cli by default run on port 8545 also check if you have imported the right account.
If it doesn’t work try to logout from metamask, restart your server and reload the page. It’s a common issue with metamask when you are switching to an other network.
How did you deployed it with remix or truffle migrate ?

1 Like

I did run it on the port 8545, through truffle migrate, I’ll check whether logging out and restarting the server and the page helps, I’ll let you know, I’m feeling a bit helpless, all I get are errors and I spend hours on Stack overflow :frowning_face:

I got this error many time when developing it s really annoying. When did you get the error ? Did you send fund to your contract ? I tried it on my side with the function i sent you and it works.

@gabba I’ve tried everything, I still get the same error when calling the bet function from address accounts[2]. It used to work with regular GUI ganache, what didn’t work was the listening of events, not the transactions themselves. Now I did the same on the GUI, the transaction worked, everything under the hood worked as expected, however I still don’t see any bet event appearing in the console, it outputs and empty JSON object. I can’t even get the return value of the flip function. When I open the transactionInstance JSON, under events, bets, I see this error TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.invokeGetter (<anonymous>:1:142), I tried playing with the truffle console and I can see the events happening in the logs, they just don’t show in the console.

@gabba THANK YOU FROM THE BOTTOM OF MY HEART, I can finally rest, it worked!!! I inspected the javascript source of my server in the browser and there were cached versions of the main.js file. It turns out I was running the same wrong file again and again. I feel so stupid, but I’m glad I figured it out.

1 Like

Great i’m glad you solved it :slight_smile:

Ok, this was cool! :slight_smile: From 0 to a full dapp with 0 previous experience besides this academy courses. I was a Backend Developer before, though…

My code: https://github.com/PedroMD/eth201-coinflip
Screen recorder: https://recordit.co/LSFDuiwX2I (can record a simpler one, if needed)

In one of the videos, you mentioned the use of emit to get the web app to know what the SC did, so that’s what I’ve implemented… Is this the right way to doing it?

1 Like

Hey guys! Any tips before starting the project? I have no experience as a developer at all so any suggestions on how to start would be much appreciated. Maybe start some solidity code on Remix? I guess I should not use the old Ethereum course as reference even though Filip made a similar dapp there, ritgh? I also see most of you uploaded it through github, should I use it?
Thanks a lot for your help!