3

I have a very strange problem. Many solidity contract examples use address struct types as state variables. But my smart contract:

pragma solidity ^0.4.0;

contract ProductItem {
address[] _owners;
address _currentOwner;
address _nextOwner;
string _productDigest;

function ProductItem(string productDigest) {
    _currentOwner = msg.sender;
    _productDigest = productDigest;
}

function setNextOwner(address nextOwner) returns(bool set) {
    if (_currentOwner != msg.sender) {
        return false;
    }
    _nextOwner = nextOwner;
    return true;
}

function confirmOwnership() returns(bool confirmed) {
    if (_nextOwner != msg.sender) {
        return false;
    }
    _owners.push(_nextOwner);
    _currentOwner = _nextOwner;
    _nextOwner = address(0);
    return true;
}

function getOwner() constant returns(address owner) {
    return _currentOwner;
}

function getOwners() constant returns(address[] owners) {
    return _owners;
}

function getProduct() returns (string product) {
    return _productDigest;
}
}

gives me error in web ide:

Untitled:4:5: Error: Type "address[]" not supported for state variable.
address[] _owners;
^---------------^"

If i ignore this error and try to deploy and call function, e.g. getProduct() it results with null.

2
  • This appears to be a package problem. Having the same issue with the solc npm package, just for one address, not even an array. Compiles fine in browser-solidity.
    – Joël
    Dec 21, 2016 at 6:20
  • i have a same issue, transactions are happening but i am not able to see the count and item details can anyone resolve this?
    – Sagar
    Feb 7, 2017 at 7:24

1 Answer 1

1

I've used the Solidity realtime compiler and runtime connected to a local geth node with version Geth/v1.4.13-stable/linux/go1.5.1 and your code compiles and deploys perfectly.

I have made one change and that is to add constant keyword to the getProduct(...) method as you are not changing any state in this method.

Here is the modified code:

pragma solidity ^0.4.0;

contract ProductItem {
    address[] _owners;
    address _currentOwner;
    address _nextOwner;
    string _productDigest;

    function ProductItem(string productDigest) {
        _currentOwner = msg.sender;
        _productDigest = productDigest;
    }

    function setNextOwner(address nextOwner) returns(bool set) {
        if (_currentOwner != msg.sender) {
           return false;
        }
        _nextOwner = nextOwner;
        return true;
    }

    function confirmOwnership() returns(bool confirmed) {
        if (_nextOwner != msg.sender) {
            return false;
        }
        _owners.push(_nextOwner);
        _currentOwner = _nextOwner;
        _nextOwner = address(0);
        return true;
    }

    function getOwner() constant returns(address owner) {
        return _currentOwner;
    }

    function getOwners() constant returns(address[] owners) {
        return _owners;
    }

    function getProduct() constant returns (string product) {
       return _productDigest;
    }
}

Here is the screen showing the deployment of the modified code, and that the constant method getProduct() returns "ProductOne".

enter image description here

1
  • 1
    Thanks for answer! Actually, for now non-constant version of getProduct() also works in web ide. Maybe it is an issue with a library (Nethereum .net).
    – forik
    Oct 2, 2016 at 13:12

Your Answer

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

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