Solidity Basics

We’re glad to have you here! Good luck :slight_smile:

Hi @filip, I hope that this thread is the right one to post my issue. I am building my first dapp and I am stuck now. I built a contract that emits two events and through web3.js I am trying to process them. On Brave browser everything works as it has to, but with Opera browser it is not. Opera do not recognize when the event happens. If I try to console.log anything directly after event, console is silent. Can you help me please? This is my code that handles the event, thanks.

kotloContract.events.allEvents()
      .on('data', (event) => {
        if (event.event == "newCard"){
          cardMessage(event.returnValues[3], event.returnValues[0], event.returnValues[1], event.returnValues[2], event.returnValues[4]);
        }
        else if (event.event == "newUser"){
          userMessage(event.returnValues.name);
        }
      })
      .on('error', console.error);

I have this mapping contract but i get this error when deploying

browser/Untitled.sol:26:3: TypeError: Member “height” not found or not visible after argument-dependent lookup in struct HelloWorld.Person memory.
newPerson.height = height;
^--------------^

and this is my code

pragma solidity ^0.5.12;



contract HelloWorld {

    struct Person{
        
        string name;
        uint age;
        uint heigt;
    }
    
  mapping(address=>Person) private people;
  
  
  
  function createPerson(string memory name, uint age, uint height ) public {
      address creator = msg.sender;
      

  //Create Person
  Person memory newPerson;
  newPerson.name = name;
  newPerson.age = age;
  newPerson.height = height;
  
  
  people['creator'] = newPerson;
  }
  
  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);
  }
  
}

i cant find the error

1 Like

Hey @yayo, looks like you have a little tipo in your Person strucs declaration.

struct Person{
        
        string name;
        uint age;
        uint heigt; => uint height; 
    }
5 Likes

thanks, i didnt see that
i was trying to find this sine 10 hours now
thanks

2 Likes

About the types video: I notice that you’re using ‘uint’, which upon closer inspection is ‘unsigned integer’, meaning there’s no sign bit and you can’t code negative numbers. Might want to mention that.

Upon closer closer inspection ‘uint’ is acting like a template for ‘uint32’, ‘uint64’, ‘uint128’, etc. As a scientific programmer I find that both very awesome and very sloppy (for hardware-in-the-loop purposes). Even C allows you to slice off memory by-the-bit for extreme efficiency.

And speaking of: where are the floating point types? What are we coding here, a BASIC Stamp?!? What if I wanted to send $4.95?

I’m not even asking for anything mathematically useful like Fortran’s ‘complex’ or a ‘rational’, or a ‘quaternion’ type. Solidity thus far seems useless for engineering problems like orbit mechanics or drone control systems. And I suppose that’s fair considering the gas costs.

So apparently Solidity is designed for bean counting–WHOLE beans only! None of that split pea nonsense.

1 Like

Where are mappings in ethereum stored?
somewhere in memory? storage? :thinking:

welcome to programming, where most of the time you are searching why something doesn’t work :grinning: #debugging

5 Likes

sending 4.95 dollars in ether is just some number in ‘Wei’

1 Like

That’s right, ethereum (the EVM) doesn’t support floating point numbers. Due to the nature of floats and their unpredictability we can’t use them in a consensus based system.

1 Like

Ok, I get why.
And all the floating points can be created in the JavaScript front-end.
I considered making a “Ye Olde Rational” type:

struct Rational {
    uint ordinal;
    uint numerator;
    uint denominator;
...
}

…but why waste all that gas.
Uncle.
After 25 years of scientific programming (in Fortran) Solidity feels like Flatland. https://www.youtube.com/watch?v=RbTUTNenvCY

2 Likes

@filip Seems using quotes on text in set function is not required. When pressing message with and without quotes result is the same.

3 Likes

Maybe it does. I can remember some time I had issues with that and I had to use quotes in remix. Maybe it has changed. However, it’s a good habit to have to put quotes around your strings. In truffle you would have to, for example.

1 Like

Dear @filip and colleagues, I have one question that I can’t figure out.
Why do I need to write Person memory newPerson; ?
Why can’t I populate the struct by writing Person.name / Person.age etc…

Is there a specific reason or it is just the syntax of Solidity?

The rest is all extremely clear :slight_smile: Thanks a lot!!

2 Likes

Great question!

The answer is that the struct that we create by writing struct Person {…} is just a definition of the structure. It’s like the architects drawing of a house, it’s just the definition of the house and not the actual house.

When we write Person memory newPerson we create an actual Person according to the definition we created. It would be like we built a house according to our drawings. And we can do that over and over again.

Was that clear? Let me know if you have more questions.

3 Likes

Hi Filip, you demonstrated in your first Solidity video how to increase the font size in the Remix editor by moving the mouse. But how do you do that? The Remix documentation seems to be outdated here. Thank you.

In the old remix editor you do it with these small + and minus signs. But I haven’t found them in the new version. But luckily, when you go to remix you can still choose to use the old version, which is fine.

image

Yes, I understand. However in your first video named “Build Tools - Remix Walkthrough” you are using the NEW remix editor as well (without these small +/- signs) and you are easily changing the font size, see your video at 2:40 min.

Oh right, I forgot about that. Thanks for reminding me of the timestamp. Makes it easy for me to check.

In the new editor you can zoom in with ctrl and “+” key or zoom out with ctrl and “-” key on your keyboard. Sorry for the confusion. With so many videos it’s easy to forget what I’m doing :smiley:

Perfect, now it’s working. Thank you.
This feature is quite hidden and the documentation is outdated, still showing the old +/- icons. Thanks again.

1 Like