1

TypeError: Invalid type for argument in function call. Invalid implicit conversion from bytes calldata to uint256 requested. proposals.push(msg.data);

pragma solidity ^0.4.17;

    contract FantasyLeague {
        // Define addresses of league members
        address public member;
        // Hold data of proposed number
        uint[] public proposals;

        // Deploy contract
        constructor() public {
            member = msg.sender;
        }

        // Propose new team number
        function proposeNumber (uint) public payable {
            require(msg.value > .01 ether);
            proposals.push(msg.data);
        }

        // Retrieve List of current proposals
        function getProposals () public view returns (uint[]) {
            return proposals;
        }
    }

2 Answers 2

0

It's unclear what you're trying to do, but you probably just want this:

function proposeNumber(uint number) public payable {
    require(msg.value > .01 ether);
    proposals.push(number);
}
4
  • Thanks smarx! I now realize I also need to ensure users don't vote with multiple account addresses which can be generated quite easily. What would be the easiest way to ensure that? Through a modifier? Or perhaps through some delegate function?
    – kefa
    Aug 12, 2018 at 20:30
  • I'm unclear on your requirement. Can you define what a "user" is and how it differs from an "account?"
    – user19510
    Aug 12, 2018 at 20:56
  • A user is someone in our league who needs to cast a vote. If a user is utilizing Meta Mask to cast their vote, can't they produce multiple "addresses" on their Meta Mask account and theoretically have multiple votes by the same person?
    – kefa
    Aug 13, 2018 at 16:45
  • Yes. It's impossible from within a smart contract to know something about the identity of a human. You'd need some external vetting process (like whitelisting one address per human who presents an ID to you in person or something like that).
    – user19510
    Aug 13, 2018 at 16:47
1

since msg.data is bytes and here proposals is array of uint256 you need convert bytes to uint

 function proposeNumber () public payable {
           uint temp;
           require(msg.value > .01 ether);
           // bytes calldata is not implicitly convertible to expected type storage pointer so use memory
            bytes memory b = msg.data;
            for(uint i=0;i<b.length;i++){
            temp = temp + uint(b[i])*(2**(8*(b.length-(i+1))));
            }
            proposals.push(temp);
         }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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