2

Why does getProduct(..) always return an empty address 0x00 on browser-solidity?

pragma solidity ^0.4.7;

contract Products {
    struct Product {
        bytes32 name;
        uint votes;
        address company;
    }

    mapping (uint => Product) products;
    mapping (address => uint) companyProductsCounter;
    uint private counter;

    function Products () {
        counter = 0;
    }

    function registerProduct( bytes32 productName) {
        products[counter++] = Product({name: productName, votes: 0, company: msg.sender});
    }

    function getProduct(uint code) constant returns (bytes32 name, uint votes, address company) {
        products[code].name;
        products[code].votes;
        products[code].company;
    }
}
  • 1
    How are you calling the getProduct function? – atomh33ls Jan 6 '17 at 17:22
3

Could it because the return parameters of getProduct(unit) are left unset?

Try:

function getProduct(uint code) constant returns (bytes32 name, uint votes, address company) {
    name=products[code].name;
    votes=products[code].votes;
    company=products[code].company;
}

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.