Is there a way to access Ethereum Smart Contract's variables by name in JavaScript? Say I have a simple smart contract:

contract Simple {
    string32 message;

    function Simple() {
        message = "Hello world!";
    }
}


How can I easily access the message variable by name in JavaScript? It looks like there is some way to map functions into JS, but variables appear to only be accessible through a complicated way:

var storageObject = web3.eth.storageAt(contractAddress);
document.getElementById('fullName').innerText = web3.toAscii(storageObject['0x']) + ' ' + web3.toAscii(storageObject['0x01']);
Note that this question has been automatically mapped to reddit and answered there.

If you declare your state variables as public, a function to read their values will be automatically created by the compiler ("accessor function"). If you use the rich interface provided by web3.js, you can create a javascript contract object and just call message() on that to get the respective value.

For arrays and mappings, the compiler will generate a function that has additional arguments which correspond to the indexes. For example, for a variable mapping(uint =&gt; uint[]) public data; the function will be equivalent to function data(uint x, uint y) constant returns (uint) { return data[x][y]; }.