10

I was following the Greeter tutorial on Go Ethereum wiki and got stuck on the "var greeterContract = web3.eth.contract(greeterCompiled.greeter.info.abiDefinition)" phase returning TypeError: Cannot access member 'info' of undefined. I have solC installed and linked - (eth.getCompilers() returns ["Solidity"]) and source code compiled.

The only difference I spotted against the tutorial and other posts in the forum is that viewing greeterCompiled has "stdin"-block before greeter and mortal attributes. Any ideas what causes the error / stdin-block?

Geth Version: 1.5.8-stable-f58fb322 and solC Version: 0.4.9+commit.364da425.Linux.g++

{
  <stdin>:greeter: {
    code: "0x6060604052341561000c57fe5b6040516102f03803806102f0833981016040528051015b5b60008054600160a060020a03191633600160a060020a03161790555b805161005390600190602084019061005b565b505b506100fb565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061009c57805160ff19168380011785556100c9565b828001600101855582156100c9579182015b828111156100c95782518255916020019190600101906100ae565b5b506100d69291506100da565b5090565b6100f891905b808211156100d657600081556001016100e0565b5090565b90565b6101e68061010a6000396000f300606060405263ffffffff60e060020a60003504166341c0e1b5811461002c578063cfae32171461003e575bfe5b341561003457fe5b61003c6100ce565b005b341561004657fe5b61004e610110565b604080516020808252835181830152835191928392908301918501908083838215610094575b80518252602083111561009457601f199092019160209182019101610074565b505050905090810190601f1680156100c05780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000543373ffffffffffffffffffffffffffffffffffffffff9081169116141561010d5760005473ffffffffffffffffffffffffffffffffffffffff16ff5b5b565b6101186101a8565b60018054604080516020600284861615610100026000190190941693909304601f8101849004840282018401909252818152929183018282801561019d5780601f106101725761010080835404028352916020019161019d565b820191906000526020600020905b81548152906001019060200180831161018057829003601f168201915b505050505090505b90565b604080516020810190915260008152905600a165627a7a723058202c65e52fe69886136391b3ad7b56f7b9b5ab3474a50940ab214964258d3133000029",
    info: {
      abiDefinition: [{...}, {...}, {...}],
      compilerOptions: "--combined-json bin,abi,userdoc,devdoc --add-std --optimize",
      compilerVersion: "0.4.9",
      developerDoc: {
        methods: {}
      },
      language: "Solidity",
      languageVersion: "0.4.9",
      source: "contract mortal { address owner; function mortal() { owner = msg.sender; } function kill() { if (msg.sender == owner) suicide(owner); } } contract greeter is mortal { string greeting; function greeter(string _greeting) public { greeting = _greeting; } function greet() constant returns (string) { return greeting; } }",
      userDoc: {
        methods: {}
      }
    }
  },
  <stdin>:mortal: {
    code: "0x6060604052341561000c57fe5b5b60008054600160a060020a03191633600160a060020a03161790555b5b609c806100386000396000f300606060405263ffffffff60e060020a60003504166341c0e1b581146020575bfe5b3415602757fe5b602d602f565b005b6000543373ffffffffffffffffffffffffffffffffffffffff90811691161415606d5760005473ffffffffffffffffffffffffffffffffffffffff16ff5b5b5600a165627a7a72305820eca3dc2bc8d6fa1918006106610ba8497fc2dbc338fbd528482ddd442ab88be50029",
    info: {
      abiDefinition: [{...}, {...}],
      compilerOptions: "--combined-json bin,abi,userdoc,devdoc --add-std --optimize",
      compilerVersion: "0.4.9",
      developerDoc: {
        methods: {}
      },
      language: "Solidity",
      languageVersion: "0.4.9",
      source: "contract mortal { address owner; function mortal() { owner = msg.sender; } function kill() { if (msg.sender == owner) suicide(owner); } } contract greeter is mortal { string greeting; function greeter(string _greeting) public { greeting = _greeting; } function greet() constant returns (string) { return greeting; } }",
      userDoc: {
        methods: {}
      }
    }
  }
}
4
  • 1
    See ethereum.stackexchange.com/questions/2751/… for a step-by-step guide to deploying Greeter. Commented Feb 4, 2017 at 4:22
  • Thanks @BokkyPooBah! I was following this guide and did it once again to avoid demo effect. But as before, I'm getting same error. When the source is compiled, it has this <stdin> block before greeter and mortal attributes. I'm not sure is that the problem but again I'm getting error Cannot access member 'info' of undefined and the only difference I can find against the step-by-step guide is the <stdin> block.
    – Henrik
    Commented Feb 4, 2017 at 10:24
  • 1
    I can reproduce your problem. Most likely due to the new version of Solidity. I'll investigate and get back to you. Commented Feb 4, 2017 at 11:09
  • The new Solidity 0.4.9 3 days talks about "watching out for file prefixes" - github.com/ethereum/solidity/releases/tag/v0.4.9 . <stdin> is the file prefix for "standard input", when no file prefix is specified. I'll try to work out a work-around and get back to you. Commented Feb 4, 2017 at 11:12

2 Answers 2

9

Update Apr 23 2017

geth 1.6.0 has a breaking change to remove access to the Solidity compiler from within geth.

The workaround is detailed in How to compile Solidity contracts within geth with the v1.6.0 **BREAKING CHANGE**?



Note: Solidity 0.4.9 has a breaking change to a lot of old examples

The new Solidity 0.4.9 3 days ago mentions that you have to be "watching out for file prefixes" - https://github.com/ethereum/solidity/releases/tag/v0.4.9 . <stdin> is the file prefix for "standard input", when no file prefix is specified.

The workaround is to use:

greeterCompiled["<stdin>:greeter"]

instead of:

greeterCompiled.<stdin>:greeter

as the < character will cause problems in the geth command line interpreter.



Details

To compile the greeter example using Solidity 0.4.9, you will have to modify your instructions slightly.

Following are the instructions to work-around the standard Greeter example.

Compile your contract:

var greeterSource = 'contract mortal { address owner; function mortal() { owner = msg.sender; } function kill() { if (msg.sender == owner) suicide(owner); } } contract greeter is mortal { string greeting; function greeter(string _greeting) public { greeting = _greeting; } function greet() constant returns (string) { return greeting; } }';

var greeterCompiled = web3.eth.compile.solidity(greeterSource);

If you now look at your greeterCompiled variable, you will see that some members are prefixed with <stdin>, as mentioned in the Question above.

> greeterCompiled
{
  <stdin>:greeter: {
    code: "0x6060604052341561000c57fe5b6040516102f03803806102f0833981016040528051015b5b60008054600160a060020a03191633600160a060020a03161790555b805161005390600190602084019061005b565b505b506100fb565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061009c57805160ff19168380011785556100c9565b828001600101855582156100c9579182015b828111156100c95782518255916020019190600101906100ae565b5b506100d69291506100da565b5090565b6100f891905b808211156100d657600081556001016100e0565b5090565b90565b6101e68061010a6000396000f300606060405263ffffffff60e060020a60003504166341c0e1b5811461002c578063cfae32171461003e575bfe5b341561003457fe5b61003c6100ce565b005b341561004657fe5b61004e610110565b604080516020808252835181830152835191928392908301918501908083838215610094575b80518252602083111561009457601f199092019160209182019101610074565b505050905090810190601f1680156100c05780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000543373ffffffffffffffffffffffffffffffffffffffff9081169116141561010d5760005473ffffffffffffffffffffffffffffffffffffffff16ff5b5b565b6101186101a8565b60018054604080516020600284861615610100026000190190941693909304601f8101849004840282018401909252818152929183018282801561019d5780601f106101725761010080835404028352916020019161019d565b820191906000526020600020905b81548152906001019060200180831161018057829003601f168201915b505050505090505b90565b604080516020810190915260008152905600a165627a7a723058202c65e52fe69886136391b3ad7b56f7b9b5ab3474a50940ab214964258d3133000029",
    info: {
      abiDefinition: [{...}, {...}, {...}],
      compilerOptions: "--combined-json bin,abi,userdoc,devdoc --add-std --optimize",
      compilerVersion: "0.4.9",
      developerDoc: {
        methods: {}
      },
      language: "Solidity",
      languageVersion: "0.4.9",
      source: "contract mortal { address owner; function mortal() { owner = msg.sender; } function kill() { if (msg.sender == owner) suicide(owner); } } contract greeter is mortal { string greeting; function greeter(string _greeting) public { greeting = _greeting; } function greet() constant returns (string) { return greeting; } }",
      userDoc: {
        methods: {}
      }
    }
  },
  <stdin>:mortal: {
    code: "0x6060604052341561000c57fe5b5b60008054600160a060020a03191633600160a060020a03161790555b5b609c806100386000396000f300606060405263ffffffff60e060020a60003504166341c0e1b581146020575bfe5b3415602757fe5b602d602f565b005b6000543373ffffffffffffffffffffffffffffffffffffffff90811691161415606d5760005473ffffffffffffffffffffffffffffffffffffffff16ff5b5b5600a165627a7a72305820eca3dc2bc8d6fa1918006106610ba8497fc2dbc338fbd528482ddd442ab88be50029",
    info: {
      abiDefinition: [{...}, {...}],
      compilerOptions: "--combined-json bin,abi,userdoc,devdoc --add-std --optimize",
      compilerVersion: "0.4.9",
      developerDoc: {
        methods: {}
      },
      language: "Solidity",
      languageVersion: "0.4.9",
      source: "contract mortal { address owner; function mortal() { owner = msg.sender; } function kill() { if (msg.sender == owner) suicide(owner); } } contract greeter is mortal { string greeting; function greeter(string _greeting) public { greeting = _greeting; } function greet() constant returns (string) { return greeting; } }",
      userDoc: {
        methods: {}
      }
    }
  }
}

Using < on your your geth JavaScript command line will not work. So here is a temporary workaround. You can access greeterCompiled.<stdin>:greeter: in geth JavaScript using the following syntax:

greeterCompiled["<stdin>:greeter"]

So to execute the rest of the example:

var greeter = greeterContract.new(_greeting,{from:web3.eth.accounts[0],
  data: greeterCompiled["<stdin>:greeter"].code, gas: 1000000}, function(e, contract) {
  if (!e) {
    if (!contract.address) {
      console.log("Contract transaction send: TransactionHash: " +
        contract.transactionHash + " waiting to be mined...");

    } else {
      console.log("Contract mined! Address: " + contract.address);
      console.log(contract);
    }

  }
})
1
  • Whats the step for greeterContract. I get the error TypeError: Cannot access member 'info' of undefined.
    – Jus12
    Commented Feb 10, 2017 at 13:19
2

There are still more breaking changes in the newest Solidity. I used the following to fix my error in 0.4.9 latest commit.

copy file name from here

You need to copy the filename from the compiled code. In my example, this is /tmp/geth-compile-solidity311107485. Then use this in the next step. See screenshots.

paste file name here

The command to use is:

greeterCompiled["/tmp/geth-compile-solidity311107485:greeter"].info

instead of greeterCompiled.greeter.info.

Your Answer

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

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