Solidity Basics

pragma solidity 0.5.12;


contract HelloWorld{
    
    struct Person{
        string name;
        uint age;
        uint height;
        bool senior;
    
    }
    
    mapping(address => Person) private people; 
    
    function createPerson(string memory name, uint age, uint height) public{
        address creator = msg.sender;
      
       Person memory newPerson;
       newPerson.name = name;
       newPerson.age = age; 
       newPerson.height = height;
       
       if(age >= 65){
           newPerson.senior = true;
       }
     
       else{
           newPerson.senior = false;
       }
       
       people[creator] = newPerson;
       
       
       //THIS IS THE OTHER EXAMPLE
       //people.push(Person(people.length, name, age, height));
        
    }
    
    function getPerson() public view returns(string memory name, uint age, uint height, bool senior){
        address creator = msg.sender;
        return (people[creator].name, people[creator].age, people[creator].height, people[creator].senior);
    }
        
        
 }

HAPPY DAYS !!! :smiley:

2 Likes

contract HelloWorld {
string private message = ā€œHelloā€;

function getMessage() public view returns(string memory){
    return message;
}

So what happens when you have multiple string variables above the function getter?
How would we specify which string we want Solidity to return?

Thank you.

1 Like

contract HelloWorld {
string private message = ā€œHelloā€;
string private message1 = ā€œAnother Helloā€;

function getMessage() public view returns(string memory){
    return message1;
}

Do you mean what happens in this case?

1 Like

Hello @Lucus, hope you are great.

Now, functions can only return many variables, in case of you need to return many values you can try to return an array for example, in case of a multiple string variables.

Here is a quick code to give you a better example:

pragma solidity 0.5.12;
pragma experimental ABIEncoderV2;

contract HelloWorld{

    string[] _myArray;
    
    string _words = "HelloWorld";
    function fillArray() public{
        _myArray.push(_words);
    }
    
    
    function getArray() public view returns(string[] memory){
        return _myArray;
    }
}

If you have any more questions, please let us know so we can help you! :slight_smile:

Carlos Z.

1 Like

OK, progress is being made, but when do I get to build my Crypto, and, most importantly, how do you connect a front page - I assume website - to something where the user can actually buy the tokens?
When do we get to learn how to build a functioning ICO that can make us some money?
Impatient, I know, but time is of the essence here.
Actually, I would really like someone to explain this to me because I need to start connecting the dots in my head.
Draw me a diagram please!
DOODESVILLE :nerd_face: :grinning: :smiley: :smile: :upside_down_face: :wink:

:muscle: :partying_face:
Well done for persevering!

2 Likes

Yes, I think he did.
This is a good explanation for you @Lucus, in case you haven’t seen it :slight_smile:

I think you are confusing the following two pieces of code:

returns(string memory)  // in the function header
/* This doesn't reference a string variable:
   it just defines the data type of the value to be returned (here, a string) */

return message;  // in the function body
/* This return statement references the specific string variable to be returned.
   It does this using the name (identifier) of the variable (here, message).
   As @bitcoindoctor has illustrated, this could be any string variable defined
   within our contract: message1, message2, anyStringVariable...
2 Likes

Hi @doodesville,

That’s great that you are so keen to start linking a frontend (user interface) to a backend (smart contracts). However, you need to be able to walk before you can run. I assume you’ve already completed the JavaScript Programming for Blockchain Developers course which covers the basics of HTML and JavaScript, both essential for building a frontend. CSS is also needed for the styling, and a great way to quickly aquire a working knowledge of all three, and Solidity, and then put this knowledge into practice by building your own dapp (decentralised application) complete with frontend and backend, and capable of being deployed on the Ethereum blockchain, is the Blockchain Developer Bootcamp. Alternatively, you will cover these skills in the 201 course following this one. But you need to aquire the fundamentals first. You can only start connecting the dots when you have all the dots in place to begin with.
However, while you’re learning these fundamentals, I highly recommend doing your own research in terms of the bigger picture, as this will certainly help you to get more of a general idea about what you’re aiming for. :smiley:
In terms of programming your own tokens, again, you need to learn the fundamentals first before you can start to understand the code, best practices, standards and security implications and solutions involved in doing this. You will be ready to start covering this after completing this 101 course, and you can do this in the 201 course, Smart Contract Security course, or in the Bootcamp. :smiley: :muscle:

1 Like

Thank you both @bitcoindoctor & @jon_m :smiley:

1 Like

It’s been a couple weeks since I started this course, I’m now at the last part of ETH programming course 201 and just wondering if this seems to function well? I might be overlooking something - maybe @jon_m or @thecil can help me out! :smiley:

pragma solidity 0.7.0;
// SPDX-License-Identifier: UNLICENSED

contract CoinToss {
    uint public betChoice = 3;
    uint outcome;

    event BetOutcome(address userAddress, uint amount, bool winOrLose);

    function setBet(uint _setBet) external payable {
        require(msg.value == 1 ether, "please send 1 ether to play");
        require(_setBet == 0 || _setBet == 1, "please choose either 1 or 0");
        betChoice = _setBet;
    }


    function tossCoin() external payable {
        require(address(this).balance == 1 ether, "you must select 0 or 1 prior to tossing");
        require(betChoice != 3, "send 1 ether to choice between 0 or 1");
        
        outcome = block.timestamp % 2;
        
        
        if(outcome == betChoice) {
            msg.sender.transfer(msg.value*2);
            betChoice = 3;
            emit BetOutcome(msg.sender, msg.value, true);
        } else {
            betChoice = 3;
            emit BetOutcome(msg.sender, msg.value, false);
        }
    }
    
}
1 Like

Hi There
Should i take the old course first before taking this new one

What do you recommend
Please a reply as soon as possible

1 Like

Hey @Cryptoinsight, hope you are great.

You should start with our new courses, its an upgraded version of the old course, so you will find new lessons :nerd_face:

Carlos Z.

Your code compile and deploy great for me :slight_smile:

Is there anything specific that you are looking for?

Carlos Z.

Thank you

For clarity, you mean i should take the ethereum smart contract programming 101 and 102 instead of old ethereum programming

1 Like

yep, take the 101 and then 201, forget about the old one :nerd_face:

Carlos Z.

1 Like

What would be the next step from here?
I’m not that confident with building a front end support from scratch :grimacing: + I thought front ends were made with react (I haven’t done that course yet).

1 Like

RELOAD IT, and every things will be fine

Our JavaScript Course and React Course will set you really quickly to start building basic (but solid) front ends.

I’m not good at front end either (dont like it, i like backend, and i’m quick on it, front end is suffering for me :roll_eyes:), but I’m still able to do a good front end, because i just learn some few coding tricks by practicing :nerd_face:

Carlos Z.

2 Likes

ivan ivan talking about making progress with legos, i think its plugin, but so far i just saw normal programming, where are the legos?

Keep getting ā€˜Declaration error: Identifier not found or not unique’ on line 15 when try compile this!! Any ideas? Guessing its simple error somewhere, but cannot find it. Feel sure I’ve got identical code to the lecture video.

pragma solidity 0.5.12;

contract HelloWorld{

struct Person {
    string name;
    uint age;
    uint height;
}

mapping(address => Person) public people;

function createPerson(string memory name, uint age, uint height) public {
 adddress creator = msg.sender;
 
 Person memory newPerson;
 newPerson.name = name;
 newPerson.age = age;
 newPerson.height = height;
 
 people[creator] = newPerson;
}

}

Any help appreciated, as I’m stuck here and cannot move forward.