0

After compiling a smart contract with solc. I'm hitting some issues and would love some pointers for debugging/troubleshooting.

Description

    $ node
    > var solc = require("solc")  
    > var src = `contract yoThere {
        string public msg;
        function yoThere() {
          msg = "Hey lol";
        }

        function greet() constant returns(string) {
          return msg;
        }
     }
     `

     > var comp = solc.compile(src)
  • Check contracts

    > comp.contracts.yoThere  
    undefined
    

Though, if I try comp.contracts it returns the whole contract. What I would like to do is comp.contracts.yoThere.bytecode for example.

I don't know if the colon before the name :yoThere is an indication of something I've done wrong:

    > comp.contracts
    { ':yoThere': 
      { assembly: { '.code': [Array], '.data': [Object] },
      // ...

Any help or pointers in the right direction would be greatly appreciated.

  • comp.contracts[":yoThere"].bytecode returns what I'm looking for. I'm not sure why : gets added in front of the contract's name at compilation. – Drew Ogryzek Nov 7 '17 at 15:13
0

According to github issue 83 for solc-js, "If you compile from something that is not a file, the compiler uses the empty file name and adds a : to separate filename and contract name."

This appears to have been introduced from solc 0.4.9.

Since the colon is added (as noted in the comment to the original question), comp.contracts[":yoThere"].bytecode provides the desired output. If having the colon added is not desired, compile from a file.

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.