Created
March 1, 2017 05:24
-
-
Save iisaint/20650b3ecdc6ae7ccdeaeb160829ea9b to your computer and use it in GitHub Desktop.
Compile a smart contract
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fs = require('fs'); | |
| const solc = require('solc'); | |
| ---- connect的部分省略 ---- | |
| /* | |
| * Compile Contract and Fetch ABI, bytecode | |
| */ | |
| let source = fs.readFileSync("./contracts/BasicToken.sol", 'utf8'); | |
| console.log('compiling contract...'); | |
| let compiledContract = solc.compile(source); | |
| console.log('done'); | |
| for (let contractName in compiledContract.contracts) { | |
| // code and ABI that are needed by web3 | |
| // console.log(contractName + ': ' + compiledContract.contracts[contractName].bytecode); | |
| // console.log(contractName + '; ' + JSON.parse(compiledContract.contracts[contractName].interface)); | |
| var bytecode = compiledContract.contracts[contractName].bytecode; | |
| var abi = JSON.parse(compiledContract.contracts[contractName].interface); | |
| } | |
| console.log(JSON.stringify(abi, undefined, 2)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment