Solidity Basics

Hi @ImRONMAN,

Hopefully, you’ve already resolved this… you are missing a closing curly bracket for your contract at the very end i.e.

contract HelloWorld {  // Here you have the contract's opening curly bracket

    struct Person { ... }

    function createPerson ( ... ) public {
    
    }  // You have this function's closing curly bracket

}  /* But this is the closing curly bracket you're missing
     (for the whole contract) */
1 Like

Hi @Rob_McCourt,

After the function header there shouldn’t be a semicolon. Instead you need to open your function body with an opening curly bracket (you already have the closing curly bracket).

You then need to state the function’s visibility, which in this example is public — this is placed after the (parameters) in the function header.

Once you’ve corrected this, the code as it stands in your post will throw other errors, so let us know if you’re still struggling with this, and we’ll help you out.

2 Likes

Hi @Rob_McCourt,

Please post your code, as we need to see your full contract to be able to identify what the error is. We also can’t test your code if you don’t post it, because we can’t copy and paste it into Remix from a screenshot. From what I can see, it looks like we’ll need to recreate the error you have, in order to be able to see what’s actually happening — and that involves us deploying your code.

2 Likes

Thanks for the reply ill get right on it. I’m watching all the videos through again…

i am stuck on deploying a Mapping function for adding a balance for an ETH address…

pragma solidity 0.5.12;


contract HelloWorld{
    
    struct Person{
        string name;
        uint age;
        uint height;
    
    }
    
    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; 
       
       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){
        address creator = msg.sender;
        return (people[creator].name, (people[creator].age, (people[creator].height);
    }
        
        
    }
}

Scratch that i know exactly what ive did… To many parentheses in `people[creator]

:slight_smile:

1 Like
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