Programming Project - Phase 1

Sort of, it’s not really a full class because structs in solidity cannot have methods. It really doesn’t matter if you separate the files or not in terms of security. It’s all up to you. If you feel like it’s an easier structure to understand you can do that.

We LOVE collaboration!

2 Likes

Hey here is my project
You can test it on Ropsten testnet just select it on metamask and refresh the page if it doesn’t work.
It’s not perfect yet i have so many things i want to implement.

Try to Rob my banks or create one and i ll try to rob it :wink:

https://mysterious-lowlands-26449.herokuapp.com

I started this project at the end of ethreum 101 few months ago i had just the basic plan. Then i went for few months on security challenges which is my other passion with blockchain so i stopped codding on blockchain.

I just apply for a premium plan so i though updating it with the new thing i learned was a good idea :wink:

Let me know what you think about it, i will add tests ,oracles and maybe nft later

1 Like

@filip can you pass data between contracts using function calls or only through storage properties? It seems when you call a function on an external contract it only returns success or failure, not data. The articles I’ve found on calling external contracts seem to use storage properties to get the data back but don’t actually explain why you can’t just return the result directly from the function call. Is there a standard pattern for this?

I ask in the context of dependency injection. In Object Orientated Programming (OOP) it would be desirable to break our coin flip app into objects like “CoinFlipService” and “BetService”. This is more modular and easier to test than including everything in one, but is this good practice in Solidity? The articles I read about calling external contracts seemed to frown upon this. Inheritance is different and seemed to be encouraged, but dependency injection… ? DI is common practice in other languages.

EDIT: can only “view” functions return data? seems as soon as the function is payable, writes to a state var, or calls an external contract the object returned is the transaction receipt and not plain data.

EDIT 2: it’s looking like only view function can actually return data, even though the compiler doesn’t complain if you attempt to return something in a non view function.

can you pass data between contracts using function calls or only through storage properties?

I’m not sure I understand your question completely. I would say the only way to do it is through function calls. The only way you can get information out of storage variables is to have a getter (view) function, isn’t it?

This is more modular and easier to test than including everything in one, but is this good practice in Solidity?

No, there is no dependency injection in solidity. You should have contracts that you inherit from where it makes sense. But you should avoid interacting with external contracts as much as possible.

can only “view” functions return data? seems as soon as the function is payable, writes to a state var, or calls an external contract the object returned is the transaction receipt and not plain data.

You can still return data. But it will be presented different in for example remix. If it’s not a view function, the data returned should be in the transaction receipt.

@filip Hello Filip, first of all, thank you very much for your great courses, I finished the Blockchain 101 and Ethereum 101 course. As someone starting fresh into the topic, they have been a great help.

I finished working on Phase 1 of the Programming Project. I haven’t realized how much of a challenge developing your own contracts was, so this was a very welcome change from just following your code.

I would appreciate it if you could check out my code in my GitHub repository. Any tips regarding how to improve my code would be very helpful.

Thank you for your kind words! I really appreciate it. Seems like many of you appreciate the project format, and I really enjoy it too. It’s fun to look at all your solutions.

I took a look at your code and I think it looks really good. Couldn’t have done it better myself. Real clean.

Wait until you get to phase 2 :sunglasses: :sunglasses: :sunglasses:

1 Like

CoinToss Project Phase 1

Hello, here’s my version of the D’App. I’ve yet to write the unit tests for the app but will be pushing the tests as I finish them to the Github repo over the coming days. I built it using React so if you’re not familiar it may be a bit hard to follow. Though the d’app is quite robust, it is packed with all sorts of functionality for your learning. Good Luck!

Source Code: https://github.com/santdeleon/coinflip/tree/develop

My video recording file was to big but heres a screenshot of how it looks.

4 Likes

I like your Ux :+1: it looks great
I ll give it a try tonight :money_mouth_face:

2 Likes

That’s awesome! I love it :heart_eyes: :heart_eyes: :heart_eyes:

1 Like

User interface ugly af but works properly :slight_smile:
I made my best to keep the code as simply as possibile.

COINFLIP PHASE 1 VIDEO

3 Likes

That’s great, thanks for sharing! Onto phase 2 :heart_eyes:

2 Likes

Really like this course so far, definitely fun to make my first smart contract on my own :grin:. Here is my phase 1 project. I still need to add some tests and withdrawal functionality to the ui.

The few struggles I’m having are these. Maybe someone has a good solution?:

  • Writing tests that involve the randomized functionality. Is there a way to mock a function/contract or something? Or is there any other way to write consistent tests for them?
  • It seems a bit difficult to get the error message from the smart contract to the client. I only seem to get an error from MetaMask with little to no information in it.


Movie:


Git repo:
3 Likes

Look nice how did you make your animation ? i m looking for this kind of stuff.

  • For the randomized function i don’t see other solution than calling it few times in the same test and check the value, as you are using now you can also store the value of now, for each flip and call it via a getter to check that now% 2 is true or false.
  • If your function fail you can emit an event in your smart contract and catch the event in your frontend.
1 Like

Thanks, good one I’ll try a solution with the events, that might do the trick indeed. Seems like others had similar issues, since there is no standard on how to return error messages from smart-contracts.

The animation consists of 2 parts in css (see https://github.com/ErnoW/flippin-coin/blob/master/client/css/main.css).
A transition on the position via transition: top 2000ms;,
and a rotation animation that loops indefinitely animation: rotate3d 500ms linear infinite;

@keyframes rotate3d {
  0% {
    transform: perspective(1000px) rotateX(0deg);
  }

  100% {
    transform: perspective(1000px) rotateX(360deg);
  }
} 

Both are applied via a class in the "transactionHash" listener.

Cool , i like the effect ! thx.

2 Likes

Looks great! Good job :heart_eyes:

1 Like

Hi Guys ,I tink I am finally done with part 1. It was very exiting ! I tink that, with that part of the course where we do project on our own, you are helping us a lot! Before getting to part 2, I need to fix one issue. I can not add decimals to the value of the bet(I can bet only whole numbers), if I add decimals it takes it as a third value and go broken.

2 Likes

@filip I must celebrate - still working on the phase 1 part of the project. I had decided to go a bit farther and use a proxy / target contract (like the Proxy Dog example). Took a few hours but I figured out how to instantiate the proxy version in my unit test module:

before(async function(){
var proxy = await FlipIt.deployed();
instance = await FlipIt_v1.at(proxy.address);
});

I hope to complete this part of the project this weekend.

Regards,

David

1 Like