Mostrar matriz de estructura dentro de matriz de estructura en reaccionar

Estoy tratando de crear una matriz 2d de diferentes tipos, uno de los usuarios ha sugerido usar struct dentro de un método struct -> ¿ matriz 2d de diferentes tipos?

Ahora me encuentro con el problema de cómo mostrarlo en mi interfaz.

Así que aquí están mis 2 estructuras:

 struct Pvote {
      address voter;
      string comment;

  }

    struct Project{
        uint id;
         int votes;
         address creator;
         string name;
        string decryption;
        string website;
        string imageLink;
        Pvote[] pvote;
       mapping(address => bool) voted;
    }
 Project[] public projects;

Ahora muestro la matriz Project de una estructura usando el método fill().map() así:

  const projectsList = await Promise.all(
      Array(parseInt(getProjects))
      .fill()
      .map((element, index)=> {
        return Contract.methods.projects(index).call()
      }));

y esto funciona perfectamente

Ahora quiero mostrar la matriz de estructuras pvote[]. Así que he creado un método en solidty para ayudarme a sacarlo de la primera estructura.

  function getPvoteStruct (uint index, uint index2 ) public view returns(address,string){
           Project memory project = projects[index];
           return(project.pvote[index2].voter, 
           project.pvote[index2].comment);
       }

Esto funciona perfectamente en Remix, sin embargo, cuando intento llamar a este método desde reaccionar:

const pVotesList = await Contract.methods.getPvoteStruct(0,0)
console.log(pVotesList)

Me da lo que parece un abi del contrato, no tengo idea de por qué: * Sí, me aseguré de que haya un proyecto en el índice 0 y que haya una estructura de votación en el índice de matriz de votos 0.

{ call: { [Function: bound _executeMethod] request: [Function: bound _executeMethod] },
  send: { [Function: bound _executeMethod] request: [Function: bound _executeMethod] },
  encodeABI: [Function: bound _encodeMethodABI],
  estimateGas: [Function: bound _executeMethod],
  arguments: [ 0, 0 ],
  _method:
   { constant: true,
     inputs: [ [Object], [Object] ],
     name: 'getPvoteStruct',
     outputs: [ [Object], [Object] ],
     payable: false,
     stateMutability: 'view',
     type: 'function',
     signature: '0x7b76417a' },
  _parent:
   Contract {
     currentProvider: [Getter/Setter],
     _requestManager: RequestManager { provider: [Object], providers: [Object], subscriptions: {} },
     givenProvider: null,
     providers:
      { WebsocketProvider: [Function: WebsocketProvider],
        HttpProvider: [Function: HttpProvider],
        IpcProvider: [Function: IpcProvider] },
     _provider:
      HttpProvider {
        host: 'https://rinkeby.infura.io/QqWsfQ60KqF4HCDRrP6I',
        timeout: 0,
        connected: true,
        headers: undefined },
     setProvider: [Function],
     BatchRequest: [Function: bound Batch],
     extend:
      { [Function: ex]
        formatters: [Object],
        utils: [Object],
        Method: [Function: Method] },
     clearSubscriptions: [Function],
     options: { address: [Getter/Setter], jsonInterface: [Getter/Setter] },
     defaultAccount: [Getter/Setter],
     defaultBlock: [Getter/Setter],
     methods:
      { projects: [Function: bound _createTxObject],
        '0x107046bd': [Function: bound _createTxObject],
        'projects(uint256)': [Function: bound _createTxObject],
        getNvote: [Function: bound _createTxObject],
        '0x192e17cc': [Function: bound _createTxObject],
        'getNvote(uint256)': [Function: bound _createTxObject],
        withdraw: [Function: bound _createTxObject],
        '0x3ccfd60b': [Function: bound _createTxObject],
        'withdraw()': [Function: bound _createTxObject],
        remove: [Function: bound _createTxObject],
        '0x4cc82215': [Function: bound _createTxObject],
        'remove(uint256)': [Function: bound _createTxObject],
        getPvoteStruct: [Function: bound _createTxObject],
        '0x7b76417a': [Function: bound _createTxObject],
        'getPvoteStruct(uint256,uint256)': [Function: bound _createTxObject],
        getNumberOfvoters: [Function: bound _createTxObject],
        '0x870b9dc9': [Function: bound _createTxObject],
        'getNumberOfvoters()': [Function: bound _createTxObject],
        getOwner: [Function: bound _createTxObject],
        '0x893d20e8': [Function: bound _createTxObject],
        'getOwner()': [Function: bound _createTxObject],
        addNewProject: [Function: bound _createTxObject],
        '0xab508964': [Function: bound _createTxObject],
        'addNewProject(string,string,string,string)': [Function: bound _createTxObject],
        getPvote: [Function: bound _createTxObject],
        '0xb7409fcf': [Function: bound _createTxObject],
        'getPvote(uint256)': [Function: bound _createTxObject],
        temppvote: [Function: bound _createTxObject],
        '0xbb35e234': [Function: bound _createTxObject],
        'temppvote(uint256)': [Function: bound _createTxObject],
        getCost: [Function: bound _createTxObject],
        '0xbd3e19d4': [Function: bound _createTxObject],
        'getCost()': [Function: bound _createTxObject],
        upVote: [Function: bound _createTxObject],
        '0xc99d8eb8': [Function: bound _createTxObject],
        'upVote(uint256,string)': [Function: bound _createTxObject],
        change_cost: [Function: bound _createTxObject],
        '0xc9bae9bc': [Function: bound _createTxObject],
        'change_cost(uint256,uint256)': [Function: bound _createTxObject],
        getProjects: [Function: bound _createTxObject],
        '0xdcc60128': [Function: bound _createTxObject],
        'getProjects()': [Function: bound _createTxObject],
        downVote: [Function: bound _createTxObject],
        '0xe3ea5ded': [Function: bound _createTxObject],
        'downVote(uint256,string)': [Function: bound _createTxObject],
        editProject: [Function: bound _createTxObject],
        '0xe41c5f6f': [Function: bound _createTxObject],
        'editProject(uint256,string,string,string,string)': [Function: bound _createTxObject] },
     events: { allEvents: [Function: bound ] },
     _address: '0x2b4Ad5532919A8fEB7bB0E555842d893C0b1F148',
     _jsonInterface:
      [ [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object] ] },
  _ethAccounts:
   Accounts {
     currentProvider: [Getter/Setter],
     _requestManager: RequestManager { provider: [Object], providers: [Object], subscriptions: {} },
     givenProvider: null,
     providers:
      { WebsocketProvider: [Function: WebsocketProvider],
        HttpProvider: [Function: HttpProvider],
        IpcProvider: [Function: IpcProvider] },
     _provider:
      HttpProvider {
        host: 'https://rinkeby.infura.io/MYAPI',
        timeout: 0,
        connected: true,
        headers: undefined },
     setProvider: [Function],
     _ethereumCall:
      { getId: [Object],
        getGasPrice: [Object],
        getTransactionCount: [Object] },
     wallet:
      Wallet {
        _accounts: [Circular],
        length: 0,
        defaultKeyName: 'web3js_wallet' } } } 
Creo que deberías usar await Contract.methods.getPvoteStruct(0,0).call(), también devolver matrices desde estructuras es una molestia. Consulte web3js.readthedocs.io/en/1.0/web3-eth-contract.html#id12
OFC lol no había visto eso. eso esta solucionado Dé una respuesta debajo de esta publicación. Lo aceptaré y le daré un representante.
dio una respuesta :)

Respuestas (2)

Creo que deberías usar

await Contract.methods.getPvoteStruct(0,0).call()

También devolver arreglos de estructuras es un dolor. Consulte web3js.readthedocs.io/en/1.0/web3-eth-contract.html#id12

Lol parece que olvidé agregar .call() al final de const pVotesList = await Contract.methods.getPvoteStruct(0,0) Gracias grandfleet -> https://ethereum.stackexchange.com/users/44781/grandfleet por el responder