solidity智能合约[56]-solc编译智能合约
1
> npm install --save solc
solc编译智能合约
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const path = require('path');
const fs = require('fs');
const solc = require('solc');
//获取文件路径 跨平台
const filepath = path.resolve(__dirname,'contracts','HelloWorld.sol');
//打印出路径 /Users/jackson/Desktop/myproject/contracts/HelloWorld.sol
//console.log(filepath);
//读取文件内容
const source = fs.readFileSync(filepath,"utf8");
// console.log(source);打印出文件中的内容
// pragma solidity ^0.4.23;
//
// contract HelloWorld{
// string public name;
//
//
// constructor(string _name) public {
// name = _name;
// }
//
// function getName() public view returns(string){
// return name;
// }
// function changeName(string _name) public{
// name = _name;
// }
//
//
// }
//编译后是一个对象,打印出来, 1代表1个智能合约文件
//console.log(solc.compile(source,1).contracts[':HelloWorld']);
module.exports = solc.compile(source,1).contracts[':HelloWorld'];
本文链接:https://dreamerjonson.com/2018/12/01/solidity-56-node-compile-contract/
版权声明:本博客所有文章除特别声明外,均采用CC BY 4.0 CN协议许可协议。转载请注明出处!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。