Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Invalid number of parameters for "addData". Got 1 expected 4! #162

Open
sabinadelasr opened this issue Apr 24, 2024 · 0 comments
Open

Comments

@sabinadelasr
Copy link

I have an error I'm doing an inventory program that saves data and should save the data in the blockchain, but for some reason I get an error when I try to pass the parameters in the function that is meant to add data I get the error Error: Invalid number of parameters for "addData". Got 1 expected 4!

THIS IS THE CODE I HOPE YOU CAN HELP ME I'm learning alone with youtube:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
contract Menu {
    //Voy a crear un mapping que guarde valores de productos y luego mostrarlos en pantalla
    //Los valores principales son  Id, nombre, cantidad y precio
    //Creo una  variable contador que tendra el valor del ID, esta variable esta afuera del struct

    uint public contador = 0;

    constructor (){
        addData(1.0, "Primer tarea de ejemplo", 27589.0, 678.0);//AQUI ESTA EL PROBLEMA
    }

    struct Productos{
        uint256 id;
        string nombre;
        uint cantidad;
        uint precio;

    }

    //Voy a crear un array que guarde esos datos la ID (filas) sera un valor uint
    // y lo Menu_BDs atributos (columnas) seran los datos del struct
    //El nombre del mapping sera Manu_BD

    mapping(uint256=>Productos) public Menu_BD;

    //Funcion para agregar datos

    function addData(uint256 _id, string memory _nombre, uint _cantidad, uint _precio) public{
        //Aqui necesito generar el Key automaticamente con un contador
        //e ir llenando con datos
        //El contador no se pasa como parametro
        Menu_BD[contador] = Productos(_id, _nombre, _cantidad, _precio);
        //al pasar como parametro el id le indicas que el ID ira por defecto
        contador ++;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant