Skip to content

Instantly share code, notes, and snippets.

@iisaint
Created March 1, 2017 05:24
Show Gist options
  • Select an option

  • Save iisaint/20650b3ecdc6ae7ccdeaeb160829ea9b to your computer and use it in GitHub Desktop.

Select an option

Save iisaint/20650b3ecdc6ae7ccdeaeb160829ea9b to your computer and use it in GitHub Desktop.
Compile a smart contract
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