1

I would like to use the console.log for displaying an array of structure. I succeed only in displaying an attribute of the structure, not the all structure.

I got this error: Member "log" not found or not visible after argument-dependent lookup in type(library console)

My structure:

struct Track {
    string title;
    uint duration; }

struct Musician {
    string name;
    Track[] tracks; }

mapping(address => Musician) Musicians;

And my function to return my data:

function getAllMusicians() /*external*/ public view returns (Musician[] memory){
    Musician[] memory musicianList = new Musician[](addressMusicianNumber);
    for (uint i = 0; i < addressMusicianNumber; i++) {
        musicianList[i] = Musicians[addressMusician[i]];
        console.log("musicianList >> ", Musicians[addressMusician[i]].name); //OK
        console.log(musicianList[i].name); //OK
        console.log(musicianList[i].tracks[0].title); //OK
        console.log(musicianList[i]); //NOK
    }

    //console.logBytes32("musicianList >> ", bytes(musicianList[0])); //NOK
    //console.log("musicianList >> ", bytes(musicianList[0])); //NOK
    //console.log("musicianList >> ", musicianList); //NOK

    return musicianList;
    //emit getMusicianList(musicianList);
}

How to get all the array of structure ? such as:

[
{
    name:'musician1',
    tracks:[
       {title: 'name1', duration: 340},
       {title: 'name2', duration: 30}
    ]
},{
    name:'musician2',
    tracks:[
       {title: 'name3', duration: 34},
       {title: 'name4', duration: 31}
    ]
}
]
DamTan
  • 189
  • 1
  • 3
  • 14

1 Answers1

1

My solution was to go into the debugger.

DamTan
  • 189
  • 1
  • 3
  • 14