请教智能合约编译的问题
undefined并不是错误,戳这里 https://bitshuo.com/topic/58dcf4990a3de8932e6f7667#58dfc8300a3de8932e6f7690 查看详细演示步骤
■网友
应该是你的geth的版本问题,1.6.0以后似乎不支持这个接口了.你可以通过本地的solc编译sol代码,或者通过node来统一进行编译部署.
下面是一个简单的基于node的编译部署代码.比如你的合约是A.sol 合约名是A,参数是
运行的脚本的参数就是 A.sol A .
当然,前提是你的节点打开8545端口,并且安装了solc,web3这俩模块.Web3 = require(\u0026#39;web3\u0026#39;);web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));process=require("process");fs=require(\u0026#39;fs\u0026#39;);solc=require(\u0026#39;solc\u0026#39;);function compile(filename){\tcode = fs.readFileSync(filename).toString()\tcompiledCode = solc.compile(code);\treturn compiledCode;}function deploy(filename,contract,arg){\tcompiledCode=compile(filename);\tcontractClass=":"+contract;\tabiDefinition = JSON.parse(compiledCode.contracts.interface)\tconsole.log(abiDefinition);\tconsole.log("\");\tVotingContract = web3.eth.contract(abiDefinition)\tbyteCode = compiledCode.contracts.bytecode\tconsole.log(byteCode);\tdeployedContract = VotingContract.new(\t\t,\t\t{data: byteCode, from: web3.eth.accounts, gas: 4700000}\t\t)}function main(){\tvar args=process.argv.splice(2);\tif(args.length!=3){\t\tconsole.log("args are wrong");\t}else{\t\tvar filename=args;\t\tvar contract=args;\t\tvar arg=args;\t\tconsole.log("filename: "+filename);\t\tconsole.log("contract: "+contract);\t\tconsole.log("args: "+arg);\t\tdeploy(filename,contract,arg);\t}}main();
■网友
今天我也出现了同样的问题,系统是ubuntu,问题还没有解决。
■网友
现在的日期:2017.10.22
【请教智能合约编译的问题】 web3.js已经从0.x版本升级到1.x版本,很多函数都变了。下边是例子:const Web3 = require(\u0026#39;web3\u0026#39;);const web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));const solc = require(\u0026#39;solc\u0026#39;);let source = "contract test { function multiply(uint a) returns(uint d) { return a * 7; }}"let compiled = solc.compile(source)let contract = \u0026#39;test\u0026#39;let contractClass = ":" + contract;let abiDefinition = JSON.parse(compiled.contracts.interface)let Abi = compiled.contracts.interfacelet Code = compiled.contracts.bytecodelet myContract = new web3.eth.Contract(abiDefinition)myContract.deploy({ data: Code }).send({ from: \u0026#39;0xc469382f43936834ceaef1c3fa67e0f796406cd7\u0026#39;, gas: 1500000, gasPrice: \u0026#39;30000000000000\u0026#39;}, function (error, transactionHash) { if (error) { console.error(error); } console.log(transactionHash)//记得写个地址不然会不能调用 myContract.options.address = \u0026#39;0xabd403c1eee32aedb3bbce90061808774be13d5c\u0026#39;// multiply是合约中的方法 myContract.methods.multiply(12).call({ from: \u0026#39;0xabd403c1eee32aedb3bbce90061808774be13d5c\u0026#39; }).then( function (result) { console.log(result) //正确结果应该是84 } )})
推荐阅读
- 汽车|传华为智能汽车部件采用三元锂电池
- 电视墙没有预留网线口,智能电视怎样上网
- 入选|
- 汽车|长安汽车:公司与华为、宁德时代三方正在联合开发智能网联电动汽车平台和产品
- 关于人工智能虚拟人的一些问题
- 六儿品车|4款能“整车升级”的智能国产车,一款电动,一款混动,两款燃油
- 智能家居的怎样切入陕西市场
- 试驾|好开实用还不贵,试驾奇瑞瑞虎5x、瑞虎3x好开:1.5T/1.5L发动机,动力与油耗兼顾好用:配置丰富、空间出色好玩:智能科技加持,安全有趣
- |WEY品牌智能驾控PK赛,读懂智能科技下的全新出行方式
- |园区人工智能产业园约巴线路开通 定制公交再增2条!
