0

I have a very simply contract. I am testing writing to the blockchain (on a private network). The contract seems to deploy successfully but I don't see "this is a hardcoded string" anywhere on my block explorer.

Can anyone help me to create a simple contract where I can write "Hello World" in a way that is viewable on the blockchain?

Here is the code I'm using now:

pragma solidity ^0.4.18;

contract TestString {

    string testStr;

    function TestString() {
        testStr = "this is hardcoded string";
    }

    function setString(string str) {
        testStr = str;
    }

    function getString() constant returns (string) {
        return testStr;
    }

    function() payable {
        revert();
    }
}
1

Ethereum defines a "World State" that contains all of the contracts storages. It is not directly part of the blockchain, but is the result of applying all the transactions.

You cannot see it directly. But you can make queries to the contract, and the contract can return appropiate values. In you example you can call the getString() and it will return the appropiate value.

You can query an arbitrary contract storage directly using web3.eth.getStorageAt. But it is not very user friendly, it is more a debugging tool.

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.