0

I have the following code snippet:

pragma solidity ^0.5.1;
  contract Puzzle {
     address payable public owner ;
     bool public locked ;
     uint public reward ;
     bytes32 public diff ;
     bytes public solution ;


    constructor () public {
       owner = msg.sender ;
       reward = msg.value ;
       locked = false ;
       diff = bytes32 (11111); // pre - defined difficulty
    }

I am getting the following error:

solc Puzzle_sha256.sol Puzzle_sha256.sol:14:12: Error: Explicit type conversion not allowed from "int_const 11111" to "bytes32". diff = bytes32 (11111); // pre - defined difficulty ^-------------^

Some body please guide me.

Zulfi.

  • Why do you need to convert a number to string? – Iftifar Taz Sep 15 at 4:34
1

First convert int_const to uint265 then convert to bytes32.

diff = bytes32 (uint256(11111));

and there is another problem with your contract. You are using msg.sender and msg.value in your constructor. For that you need to mark your constructor as payable.

constructor() payable public

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.