2

By using web3deploy on remix, it is one click to copy, and one click function for you to allow someone on the the frontend to deploy a contract you are hosting via MetaMask.

If you wanted to make that contract variable, so the data: {bytecode} field could vary based on some variables in the Solidity code, you would need to compile it and then update the data: field of your web3.js deployment.

Is there a way to make solc work on the frontend? Is there a service that lets you compile Solidity remotely?

Update: I got Eric Tang's project to compile in the browser, but I haven't figured out how to only output the bytecode, nor what regex to turn the solidity contract code into one big string.

1 Answer 1

5

I believe Remix just uses solc-js. You could do the same.

EDIT

You might want browser-solc, which is a "browserified" version of solc-js.

EDIT 2

Example usage:

<script src="browser-solc.min.js" type="text/javascript"></script>
<script>
window.onload = function() {
  BrowserSolc.loadVersion("soljson-v0.4.21+commit.dfe3193c.js", function (compiler) {
    var source = 'pragma solidity ^0.4.20;\ncontract Test { function Test() public { } }';
    var contract = compiler.compile(source, 0).contracts[':Test'];
    console.log(contract.bytecode);
  });
}
</script>
5
  • This is definitely the answer works already, though not yet the way I want, which is to just get the bytecode. The docs are not great, so I will definitely share my project once finished. Commented Mar 9, 2018 at 17:06
  • I'm having difficulty locating the method in the browser-solc. It's lightweight, but I just need the bytecode. Throwing random methods at the wall, but still only get JSON output of everything. I wish there was some documentation on the remix implementation of these features. They are parsing all of it. So am going to comb through that. There's absolutely no notes in any of these projects! It's crazy, taped together functions that jump all over. Commented Mar 10, 2018 at 13:30
  • 1
    The bytecode is in the JSON. I added working code.
    – user19510
    Commented Mar 10, 2018 at 19:59
  • Perfect! I wish I could figure out how this works, but thankfully it just does. I was resigned to parsing the mess of JSON after hearing some other answers. Minifying the code into a string seems to work as well as newline tags, I just took out the double quotes from my contract. Going to concatenate the variable terms, and make this work. Commented Mar 10, 2018 at 23:30
  • 1
    All I did was log the JSON and search for "bytecode".
    – user19510
    Commented Mar 10, 2018 at 23:45

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.