Solidity Basics

Hey guys how can I save those programs in Remix? For each episode I did a new file and had a lot of comments to explain everything but used a disk cleaning utility and all the cookies etc were removed (stupid of me!)… Can’t find any program I did. Wondering if there is another way to save them besides web based. Thanks

I am a 55 year old female, whose previous computer/Internet experience was in the mid to late 1990’s with HTML and ColdFusion. So I’m a bit rusty, and lots of things have changed since then.

Here’s the problem I have run into: I can follow along with the videos and understand the code when someone else is writing it. But when I have to do an assignment on my own and write the code from scratch, I cannot do it without lots of help.

So my questions are: Are there crypto jobs out there that don’t require coding from scratch? Or is there a developer/user interface out there that is WYSIWYG?

2 Likes

Hi @pedromndias
Unfortunately they are stored in your local storage, you can just copy and past it to a file in your drive or use remixd which is syncing remix with a folder in your file system:

https://remix-ide.readthedocs.io/en/latest/remixd.html

1 Like

Hi @wenwill
The more developer friendly interface i know for now is remix, but do not hesitate to ask for help in the forum, we will be pleased to help you.

1 Like

Thanks a lot for your reply. For the past days I have ben doing “Print as PDF” and save each program in a PDF file… Didn’t know about remixd, will check it out now. Cheers!

1 Like

Hi Filip!

How can we return a struct instance from a function? Trying to return people[index] like this does not compile

pragma solidity 0.5.12;

contract HelloWorld {

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

Person[] public people;

function getPerson(uint index) public view returns (Person) {
        return people[index]; 
    }
}

A post was merged into an existing topic: Solidity basics (by @jon_m) - Optimization / gas / Type

6 posts were merged into an existing topic: Solidity basics (by @jon_m) - Optimization / gas / Type

Hi @0xinu

Returning a structure was a “non supported feature” in some beta version of solc 0.5.x compiler .
I m not sure it is supported by the version 0.6.x
Actually the best way to achieve this is to return the structure elements:

function getPerson(uint index) public view returns (uint, string, uint, uint) {
     Person memory p = people[index];
     return (p.id ,p.name, p.age, p.height);
    }

Hello Filip. Can you help…i am on the ARRAY module in Remix. I have followed your code with the
"getNumber, setNumber is it for eg setNumber 10.1 or 10,1 etc…i have tried all variances and it won’t work. I am on the 5.12 version which you suggested and it compiled ok so i am baffled here anyone?

Thanks

@NetworkP post your code please

1 Like

Dani, thanks for reaching out, hope all is well and you are staying safe.

Below is my code you requested. I am currently coding HTML CSS and JScript which i am doing well at building websites and apps. I recently just days ago decided i’ll start backend programming also in order to naturally link a smart contract to the websites but have come across a stumble.

pragma solidity 0.5.12;

contract HelloWorld{
string public message=“Hello World again”;

uint[] public number = [1,20,45];

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

function setMessage(string memory  newMessage) public {
    message = newMessage;
}  

function getNumber(uint index) public view returns(uint){
return number[index];
}

function setNumber(uint newNumber, uint index) public {
    number[index] = newNumber;
}

}

    When i compile it, the "getNumber" function works but the "setNumber" function doesn't 

Thanks again.

Hi @NetworkP

It works if the index exist, so you can change the number for index 0, 1 , 2

But if you want to add a new element in your array you will have to push it to the array.


uint[] public number = [1, 2, 3];

function getNumber(uint index) public view returns(uint){
    return number[index];
}

// Only works for the existing index 0,1,2
function setNumberWithIndex(uint newNumber, uint index) public {
    number[index] = newNumber;
}

/*
* Allow you to append a new number to the array 
*  so after this call you can modify index 3
*/
function setNumber(uint newNumber) public {
    number.push(newNumber);
}

Hi gabba

Thanks for reaching out. Maybe i need to explain myself more clearly. The code compiles and works but for some reason only the GetNumber function works but the SetNumber function doesn’t.

I have tried 10.1 for eg and then tried a comma instead of a fullstop but still no luck.

My code is below and thanks.

pragma solidity 0.5.12;

contract HelloWorld{
string public message=“Hello World again”;

uint[] public number = [1,20,45];

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

function setMessage(string memory  newMessage) public {
    message = newMessage;
}  

function getNumber(uint index) public view returns(uint){
return number[index];
}

function setNumber(uint newNumber, uint index) public {
    number[index] = newNumber;
}

}

Oh ok, i didn’t get this was the issue, there is no floating number in solidity.
So you will have to enter 1010 and assume in your frontend you are dealing with decimals :slight_smile:

1 Like

Hi Gabba. Strange one. It’s not the code in Solidity itself it’s the constructs after you have compiled the program. Where you test that the code works. The “get” and “set” constructs that we build via the code. “Arrays” Lesson. I’m not sure i am clear on my explanation. I’ll try and mail filip direct but thanks for reaching out. :slight_smile:

I received this error msg: browser/HelloWorld.sol:22:24: TypeError: Member “lenght” not found or not visible after argument-dependent lookup in struct HelloWorld.Person storage ref[] storage ref.
newPerson.id = people.lenght;
^-----------^
I tried both methods ending with same error
my code is

pragma solidity 0.5.12; 

contract HelloWorld{
    
    //struct can consist of string, integer(uint), address
    //defines structure of this person with these properties
    struct Person{
        uint id;
        string name;
        uint age;
        uint height;
    }   
       // address walletAddress;
        
    
    //create and save instances in a array
    Person[] public people;
    function createPerson(string memory name, uint age, uint height) public{  
        //people.push( Person(people.lenght,name, age, height) );
        Person memory newPerson;
        newPerson.id = people.lenght;
        newPerson.name = name;
        newPerson.age = age;
        newPerson.height = height;
        people.push(newPerson);
    
    } 
}

You’ve spelt length incorrectly in both methods. If you correct this then that should sort it.

4 Likes

I do not understand why bool comes back false at age 65…

if(age >= 65){
           newPerson.senior = true;
       }
       else{
           newPerson.senior = false;
       }
        
    
    } 
    
    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);
        
    }
}
  • 0: string: name Georg
    *** 1: uint256: age 65**
    *** 2: uint256: height 156**
    *** 3: bool: senior false**

Hi @cherrybluemoon
Are you using the exact same contract as in the previous message ?
You need to add

bool senior;

In your structure.
Your condition should works.