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?

  • 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 7, 2017 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 7, 2017 at 18:40
  • what is printed for compiled?
    – Lee
    Feb 7, 2017 at 18:49
  • {"<stdin>: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 7, 2017 at 19:16
  • 1
    @BokkyPooBah There was a whole bunch of stuff and i missed the answer. I will post it to be clear
    – PetrosM
    Feb 9, 2017 at 12:33

1 Answer 1


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;

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.