-1

I'm trying to return the struct values contained in array everytime i push a button thet call inserimento and ritornavalore functions.

here is my code in solidity:

pragma solidity ^0.5.1;
pragma experimental ABIEncoderV2;


contract M {

    struct Confezione {
        string mar;
        uint256 co;
    }

    Confezione[] public dati;

    function inserimento(string memory m, uint256 c) public {
        dati.push(Confezione(m,c));
    }

    function ritornavalore() public view returns(Confezione[] memory) {
    return dati;

    }
}

and here the javascrypt code where i have problems:

var codiceAbi = web3.eth.contract(abi);
var connessione = codiceAbi.at(indirizzocontratto);
//richiamo la funzione get
connessione.ritornavalore.call(function (err, variabilediritorno) {
if (err) { console.log(err) }
if (variabilediritorno) {
//mostro l'array a video
document.getElementById("idcontainer").innerHTML = "Valori inseriti fino ad ora: " + variabilediritorno;
}
});
}
catch (err) {
document.getElementById("idcontainer").innerHTML = err;
}

in my js i have more code but i think here is the problem when i call ritornavalore.call maybe.

  • can you more describe that which type of problem you getting during retrieving array? – Mahesh Rajput Feb 23 at 3:46
  • I just can't see data in array @MaheshRajput – Simone R.C. Feb 25 at 14:06
0

If you are using pragma experimental ABIEncoderV2;, then you can see this

Warning: Experimental features are turned on. Do not use experimental features on live deployments.

It means there are still some issues in using experimental ABIEncoderV2; in live deployments. Nothing wrong with your solidity code.

For more information, you can see this type of questions on stack community.

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.