0
pragma solidity ^0.4.23;


contract CareerCertificate {

struct Certificate {

    bytes32 a;// existente - DUDA
    bool b;// existente - DUDA
    uint c;// existente - DUDA

    bytes32 d;
    bytes32 e;
    bytes32 f;
    bytes32 g;
    bytes32 h;


    bytes32 i;//Nuevo
    bytes32 j;//NUEVO
    bytes32 k;//NUEVO

    uint l;
    uint m;

    bool active;
}


address public ceoAddress;
address public employee;

mapping (bytes32 => Certificate) public certificates;//<___________

event CertificateCreated(address creator, string id, string RUT);
event SetActive(address responsable, string id, bool active, string description);

constructor() public {
    ceoAddress = msg.sender;
}

//funcion que crea un certificado recibe los campos y lo convierte en la variable bytes32
function createCertificate(string _a, uint _date, string _completeName, string _RUT, string _institution, string _RutInstition, string _title, string _FechaTitulacion, 
string _NroRegistro, string _CodigoVerificacion, uint _completionDate, uint _registerNumber) onlyEmployees {

    bytes32 realId = convert(_a);
    require(!certificateExists(_a));
    certificates[realId].a = a;

..... ..... ....

I have a problem that when I add a variable to the struct it shows me that error. I still have my doubts if I am doing bad mapping, because deleting the mapping or a variable of the struct eliminates the error.

2

You have too many variables in the function (including the parameters). You need to find a way to reduce the number of variables used by a single function.

If your contract is just storing those string variables and doesn't need to access them individually, consider combining some of them in a single string - for example "institutionData" - which contains all the data structured with JSON encoding or RLP encoding. You may also find it better to store the data elsewhere, such as IPFS, and only store its address/hash in the contract.

  • the create certificate function is not the same problem I did it in two sections and even so it showed me the problem but what I did was eliminate the "public" in the mapping that I have the code and it was solved. But now my question is, will it affect that the mapping does not have the "public"? – Nicolas Flores Muñoz Dec 24 '18 at 23:48
  • Marking a variable "public" causes the compiler to try to make a getter function that returns each element of the struct in an array. That function needs to use variables just as it would if you'd written it yourself, and it has the same limit on the number of variables as any other function. If that's what's breaking, either reduce the number of variables in the struct (see my answer) or, instead of marking it "public", make your own getter that leaves out some of the variables, then make an extra, different getter function if you need to be able to read the others. – Edmund Edgar Dec 25 '18 at 0:38
  • Another doubt that I have, is it possible to have a function that calls two functions that returns variable ??? – Nicolas Flores Muñoz Dec 25 '18 at 0:51

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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