2

I have a question when I use solidity to compile a simple contract. It like that:

> web3.eth.getCompilers()
["Solidity"]
> source = "contract test { function multiply(uint a) returns(uint d) { return a * 7; } }"
"contract test { function multiply(uint a) returns(uint d) { return a * 7; } }"
> source
"contract test { function multiply(uint a) returns(uint d) { return a * 7; } }"
> clientContract = eth.compile.solidity(source).test
undefined

I don't know why the result is "undefined", what is wrong? I'm using it on the mac os and also have the same question in ubuntu.

wait_lin
  • 23
  • 4
  • What happens if you just go > clientContract like you did with source? – Rob Hitchens Feb 09 '17 at 15:22
  • clientContract = eth.compile.solidity("contract test { function multiply(uint a) returns(uint d) { return a * 7; } }").test

    undefined

    Do you mean that ?

    – wait_lin Feb 10 '17 at 01:18
  • It's a feature of the JavaScript console, it always teaches you about the return value. If there isn't anything to return, it displays undefined. That does not mean your function was not successfully executed. – q9f Feb 10 '17 at 11:25
  • Thanks. You are right. I did not understand well about it. – wait_lin Feb 11 '17 at 02:26

1 Answers1

3

According to Greeter variables are all undefined and contract doesn't run undefined in javascript isn't a bad thing. Variable declarations always return undefined, its nothing to worry about.

This commands worked for me. Check it out:

var source = "contract test { function multiply(uint a) returns(uint d) { return a * 7; } }";
var compiled = web3.eth.compile.solidity(source);
console.log(JSON.stringify(compiled));
  • 1
    But I saw some information on the network it show me that return will not be 'undefined'. And it will compile the contract and return something about the result. – wait_lin Feb 09 '17 at 15:40
  • Check the commands I added to the answer. Now it seems it compiles the code. – Juan Ignacio Pérez Sacristán Feb 10 '17 at 11:43
  • I can't get the code from the contract. I think my system environment also be wrong. But I can't find what's wrong with me. – wait_lin Feb 10 '17 at 14:01
  • 1
    I solve it, very thanks to your answer. The new version solidity v0.4.9 can't use ".test". The correct command is ''contract = web3.eth.compile.solidity(source)[":test”]". – wait_lin Feb 11 '17 at 02:25