I am creating a contract where to store a sort of ADN for a game, here is the code:

pragma solidity ^0.4.22;

contract Player{
    struct ADN{
        string[] html; //direccion donde estará la imagen
        uint maxQTY;
        uint created;

ADN[] public bodies;

address public owner;

function addBody(string _html, string _html1, string _html2, string _html3, uint _maxQTY) public{
    require(msg.sender == owner);
    string [] memory images = new string[](4);
    images[0] = _html;
    images[1] = _html1;
    images[2] = _html2;
    images[3] = _html3;
        html: images,
        maxQTY: _maxQTY,
        created: 0


function showHTML(uint id) public view returns (string){
    return bodies[id].html[0];


I am trying to run it but it says the constructor must be payable, why do I need a payable constructor if I am not paying anything?

This contract it´s supouse to be called from another one when need the ADN for a player. At the momment I am just calling addBody to have a body stored as an option from the game...


The error message about payable constructor is just rubbish - the environment is trying to guess why the code fails but has clearly no idea. It is not very uncommon for error messages to be misleading around Ethereum.

It seems to work just fine assuming the following:

1) You add the missing } to the end

2) You either set the owner variable correctly or comment out the line require(msg.sender == owner); which prevents execution of the function for obvious reasons.

You can play around with it for example here: https://ethfiddle.com/IHecfUvXmd

  • you are totally right... any reason works to send that error... even a require on the code that is not successful can give you my error... Jul 18 '18 at 18:38

You have to define the owner in you constructor and it will work. Add to your code the following snippet


The message you get is only a guess from the compiler for the exception cause which is in your case not accurate.

  • I have been making tests and works with the constructor however as Lauri said after you, the error is for any reasson, even a require not met is a reason to send a constructor need to be payable... Thank you! Jul 18 '18 at 18:37

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.