0

I'm trying the following script on Node.js while running a node connected to Rinkeby Testnet (from https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethcontract):

const fs = require("fs");
const solc = require('solc')

let source = fs.readFileSync('nameContract.sol', 'utf8');
let compiledContract = solc.compile(source, 1);
let abi = compiledContract.contracts['nameContract'].interface;
let bytecode = compiledContract.contracts['nameContract'].bytecode;
let gasEstimate = web3.eth.estimateGas({data: bytecode});
let MyContract = web3.eth.contract(JSON.parse(abi));

However, this code doesn't work on my computer: when I log compiledContract I can see that the key in the mapping is :nameContract and not nameContract.

When I replace in the code nameContract by :nameContract, it works. I've checked my Solidity file and there is no mistyping errors in it.

Do you have an idea why this happens? I'm using Git BASH on Windows10.

1

I know this comes a bit late, but it's not a bug, it's a feature, see Contract name starts with colon in compiled output:

  • Report:

solc.compile(exampleContract) returns the following. It would be good to remove colon before contract name.

{
  "contracts": {
     ":NameOfContract": {...}
  }
}
  • Resolution:

To make contract references unambiguous in the output, newer compiler versions prefix every contract with :. This will be further expanded in the next version where a proper json object will be returned, so please stay tuned for a "fix".

  • Note:

I close this as it is not a "bug", just how the compiler works.

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.