Solidity Basics

Hi @Brian_Y,

This is normal for the console at the bottom of the screen to display “pending”, and below it you should then get the transaction confirmation with the green tick. Do you perhaps need to expand the console panel in oder to see it?
If it just says “pending…” and nothing else, give us some more details and a copy of the code you are trying to deploy so we can identify any possible causes.

Hi @david.maluenda,

Your Solidity code is perfect, so that should compile without any problem. Do you have more code within the contract you are trying to deploy? The error message suggests that you are trying to convert a number value to a string, or that the problem is you are using quotes in the wrong format: ‘’  instead of   " "

Where exactly are you getting the error message, in the console at the bottom of the screen or in the compiler?

Hi Filip,

I deployed the contract and …
I have “get number,” but I don’t have “Set number.” I have the exact same code as you-- I checked several times. Here is my code—what am I doing wrong?

Sincerely,
Jason

pragma solidity 0.7.5;

contract HelloWorld {

  int number; 

function getNumber() public view returns(int){
 return number;
}
  function setNumber(int _number) public {
      number = _number;
  }
}
1 Like

I understand everything you said conceptually and in terms of coding yet I do not have the same things happening when I deploy the contract. Here is my code.

pragma solidity 0.7.5;

contract HelloWorld {

  int[] numbers;
  
  function addNumber(int _number) public {
      numbers.push(_number);
  }
  
  function getNumbers(uint _index) public view returns(int[] memory){
      return numbers[_index];
    
  }

}

Hi @Jason_Mack, hope you are great.

Your contract does exactly what suppose to, set a number and get the number value. What is exactly the issue?

In this one, you only need to change the returned value in the getNumbers function, you declare that returned value is an array int [] memory, but the variable type is int, because you are returning numbers[_index] which will return a value based on the index position, and that value is integer, because you are declaring an array of integers that you call numbers (int [] numbers).

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

Carlos Z.

1 Like

pragma solidity 0.7.5;

contract Bank{
mapping (address=>uint)balance;

function addBalance (uint _toAdd)public returns(uint){
    balance [msg.sender]+= _toAdd;
    return balance[msg.sender];
}

function getBalance()public view returns (uint){
    return balance[msg.sender];
}

function transfer(address recipient, uint amount) public{
    _transfer(msg.sender, recipient, amount);
    
    //event logs and further checks
}

function _transfer(address from, adress to, uint amount) private {

    balance[from] -= amount;
    balance[to] += amount;
}

}

**// Why am i getting “identifier not found or not unique”? It is in the function _transfer **

Hi Filip,

I noticed during the array discussion you declared the first array, int[] numbers = [2,5,6]; Does that mean only integers can be in the array??

1 Like

Correct, the variable type declaration for the arrays will determine which values can only be fill on it.

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

Carlos Z.

Firstly thank you very much for this course with the great content. I have a question.

did the function of setNumber exactly as you have written the code, but whenever I enter a value like 200.0 it says error. Remix wants me to enter these values as a string. So when I type it like this “200”.“0” it has no errors.

Then I would also like to know. What is the difference between the old and the new course. I have just started with this course and I was just wondering, should I do both or just the new?

Thank you so much for all you do for this Academy.

1 Like

Hey @filip … Just wanted to say hi, i’ve completed Ivans javascript course, which as a complete beginner was tuff, i’m just starting your course now & so far it seems really well explained… i’m sure i’ll have many questions in the near future !
Thanks,
Jonathon

1 Like

Hey @FreeSpirit2222, hope you are well.

The values on Remix must be send with quote sign (""), but that does not made them an string variable, is just a syntax that remix use to send values to the smart contract, instead of a number you can try to send an string and you will receive an error, because the function is waiting for a integer variable, not a string.

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

Carlos Z.

1 Like

Great Thank you it makes perfect sense.

1 Like

Hello just starting out on solidity. Do white spaces matter in solidity?

Hey @m_tag8

Your question is too generic, it really depends where you leave blank spaces.

uint 256 a is an error;
mapping ( address => address ) b; is not an error.

Can you please clarify your question?

cheers,
Dani

Getting an error in remix while mapping the bankimg contract. I copied the code exactly but i keep getting this error and my comtract dosent update and my getBalance function dosnt work because of it

The error:

1 Like

You are missing the return keyword on your getBalance function.

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

Carlos Z.

Hi everyone,
just started out with Ethereum Smart Contract Programming 101.
I have a question regarding this Error:

“browser/AcademyTuts/Hello.sol:17:5: Warning: Function state mutability can be restricted to view function ContractDescription() public returns(string memory){ ^ (Relevant source part starts here and spans across multiple lines).”

Where does the restriction come from? How to solve this?

Hello @filip, I am wondering, how could we write a getter function to return an array that is containing structs, f. e. the people array from the structs lecture?

Hey @Bhujanga sorry for the late answer!

Warning: Function state mutability can be restricted to view function ContractDescription() public returns(string memory){ ^ (Relevant source part starts here and spans across multiple lines).”

This is not an error, is a warning.
It is basically a suggestion that the compiler is giving you.

When you have functions that do not modify the status of the blockchain (such as a getter function), you can mark them as view:

uint number = 10;
function getNumber () public view returns (uint) {
       return number;
}

Documentation: https://docs.soliditylang.org/en/v0.5.3/contracts.html#view-functions

Happy learning,
Dani

1 Like

Hey @Bhujanga

I wrote an example for you :slight_smile:

pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;


contract Test{ 
    
    struct A {
        uint number;
        uint numberTwo;
    }
    
    A [] public arrayA;
    
    function save () public {
         A memory data;
         data.number = 10;
         data.numberTwo = 20;
         arrayA.push(data);
    }   
    
    function get (uint _index) public view returns (A memory){
        return arrayA[_index];
    }
}

The function save just populates the struct and push it into the array.
The function get returns a given position of the array.

Cheers,
Dani

3 Likes