/// @dev Adds a new transaction to the transaction mapping, if transaction does not exist yet.
/// @param destination Transaction target address.
/// @param value Transaction ether value.
/// @param data Transaction data payload.
/// @return Returns transaction ID.
function addTransaction(address destination, uint value, bytes data)
    returns (uint transactionId)
    transactionId = transactionCount;
    transactions[transactionId] = Transaction({
        destination: destination,
        value: value,
        data: data,
        executed: false
    transactionCount += 1;

In In function addTransaction(address destination, uint value, bytes data)

With underlined the byte data parameter

3 Answers 3


As of Solidity 0.5.0. https://solidity.readthedocs.io/en/v0.5.0/050-breaking-changes.html

Explicit data location for all variables of struct, array or mapping types is now mandatory. This is also applied to function parameters and return variables. For example, change uint[] x = m_x to uint[] storage x = m_x, and function f(uint[][] x) to function f(uint[][] memory x) where memory is the data location and might be replaced by storage or calldata accordingly. Note that external functions require parameters with a data location of calldata.

You can fix it by saying memory for the bytes argument which is an array of byte.

pragma solidity 0.5.0;

contract Memory {
    function addTransaction(address destination, uint value, bytes memory data)
        returns (uint transactionId)
        return 0;

Warnings are safe to ignore. I wanted to keep this example as close as possible to the original and confirm it compiles.

pragma solidity >=0.4.21 <0.7.0;

contract Election {
    // Model a candidate
    struct Candidate{
        uint id;
        string name;
        uint voteCount;

    // Store candidate
    //Read/write Candidates
    mapping(uint => Candidate) public candidates;

    // Store Cnadidates Count
    uint public candidatesCount;

   constructor () public {
      addCandidate("Candidate 1");
      addCandidate("Candidate 2");
      addCandidate("Candidate 3");
      addCandidate("Candidate 4");

    function addCandidate (string memory _name) private {
        candidatesCount ++;
        candidates[candidatesCount] = Candidate(candidatesCount, _name, 0);

  • 3
    This is a code only answer. Provide explanation. Jul 17, 2020 at 10:18

For function parameter and return variables explicit data location for all variables (struct, array of mappings, string) are mandatory. You can also fix by saying string memory for he bytes argument.

pragma solidity ^0.5.7;

contract MyContract {
   function addTransaction(address destination, uint value, string memory data) 
    /* My Code ...*/

Your Answer

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

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