1

I have the following code (source is the solidity contract to be compiled).

var compiled = web3.eth.compile.solidity(source);
var code = compiled.code;
var abi = compiled.info.abiDefinition;

However compiled.code and compiled.info.abiDefinition return undefined. What am I doing wrong?

PetrosM
  • 526
  • 6
  • 16
  • Sometimes undefined gets printed to the console, but the code has still worked; have you checked typing abi into the console afterwards to check? – Lee Feb 07 '17 at 18:32
  • This is what i get. Uncaught TypeError: Cannot read property 'abiDefinition' of undefined however if i print in the console console.log(JSON.stringify(compiled)) it is not undefined – PetrosM Feb 07 '17 at 18:40
  • what is printed for compiled? – Lee Feb 07 '17 at 18:49
  • {":demo":{"code":" too long for comment ","info":{"source":"contract demo { string public name = 'Petros'; function changeName(string _newName) constant returns (string d){ name = _newName; }}","language":"Solidity","languageVersion":"0.4.9","compilerVersion":"0.4.9","compilerOptions":"--combined-json bin,abi,userdoc,devdoc --add-std --optimize","abiDefinition":[{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":true,"inputs": – PetrosM Feb 07 '17 at 19:16
  • [{"name":"_newName","type":"string"}],"name":"changeName","outputs":[{"name":"d","type":"string"}],"payable":false,"type":"function"}],"userDoc":{"methods":{}},"developerDoc":{"methods":{}}}}} – PetrosM Feb 07 '17 at 19:16
  • See http://ethereum.stackexchange.com/questions/11912/go-ethereum-greeter-tutorial-unable-to-define-greetercontract which describes the same problem and provides a work-around. – BokkyPooBah Feb 07 '17 at 21:04
  • @BokkyPooBah Still have the same problem – PetrosM Feb 08 '17 at 17:24
  • 1
    @BokkyPooBah There was a whole bunch of stuff and i missed the answer. I will post it to be clear – PetrosM Feb 09 '17 at 12:33

1 Answers1

2

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**?



This works..

var source = 'contract demo {string public name = "Petros"; function changeName(string _newName){name = _newName; } }'; 
var compiled = web3.eth.compile.solidity(source);
var abi = compiled['<stdin>:demo'].info.abiDefinition;
BokkyPooBah
  • 40,274
  • 14
  • 123
  • 193
PetrosM
  • 526
  • 6
  • 16