I'm trying to compile the following keep getting an error, even though used this before in second code and its working fine. Simply trying to change the temp to the new temperature set by the user, so that I could call/get it from Solidity. Any help on how to fix the error or achieve what I want?


uint256 public temp;
constructor() public payable {
  temp = 15;
event DataCommited( int256 T, string _L);

function commitTask(int256 _temp, string memory _location) public inState(State.Created) payable{
require (keccak256(abi.encodePacked(location)) == keccak256(abi.encodePacked(_location)));
require(_temp < 35 && _temp > -5, "Temperature out of range");
dataCount += 1;

if(dataCount == rewardNum)
            emit TaskDone();

        emit DataCommited( _temp, _location);
        _temp = temp;


Working code without an error:

uint256 age;
function setInstructor(string memory _fName, uint256 _age) onlyOwner public  {
   fName = _fName;
   age = _age;
   emit Instructor (_fName, _age);

2 Answers 2


You have uint256 temp and int256 _temp.

In _temp = temp, you are trying to assign the value of a uint256 variable to an int256 variable.

The compilation error tells you that you cannot use an implicit conversion, so use an explicit conversion instead:

_temp = int256(temp);
  • Ohh thanks, you're a life saver.
    – user51821
    Jun 20, 2019 at 7:10
  • Any ideas why in the working code I didnt get that error though?
    – user51821
    Jun 20, 2019 at 7:10
  • @user51821: In the working code, both age and _age are of the same type (uint256). Jun 20, 2019 at 8:52
  • Ohh yes, I didnt notice that. Though all along both we're same type. Thank you
    – user51821
    Jun 20, 2019 at 10:34

Because you define int256 datatype for the first argument in event DataCommited and you are passing temp that is the type of uint256.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.