智能合约环境搭建_第1页
智能合约环境搭建_第2页
智能合约环境搭建_第3页
智能合约环境搭建_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、智能合约环境搭建1 编辑器vscode + solidity 插件2 编译器 solcnpm in stall -g sole / 前提安装 node 和 npm,需要 sudo 权限 sudo apt in stall nodejs/npm或者sudo add-apt-repository ppa:ethereum/ethereumsudo apt-get updatesudo apt-get install solehttp:/solidity.readthedoes.io/en/v0.4.23/installing-solidity.html3 测试 testrpe/pip instal

2、l eth-testrpe / 前提 sudo apt install python-pip, -这个是错误的sudo npm install -g ethereumjs-testrpe4 开发框架 Trufflenpm install -g truffle5 truffle 命令1. 创建项目目录mkdir eonfereneeed eonferenee2. 创建项目truffle init3. 部署truffle migrate / deploy/在 另一个终端 里通过执行 testrpe 来启动一个节点(你也可以用 geth):回到之前的终端中,输入 truffle deploy 。这条

3、命令会部署之前 truffle init 产生的模板合约到网络上。任何你可能遇到的错误信息都会在testrpc的终端或者执行truffle的终端中输出在使用truffle migrate进行智能合约test环境发布时如果未配置正确会出现以下异常:truffle migrateError: No network specified. Cannot determine current network.at Object.detect (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:43157:23)at /usr/local/li

4、b/node_modules/truffle/build/cli.bundled.js:200497:19at finished (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:43085:9)at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:198408:14at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:68162:7at /usr/local/lib/node_modules/tr

5、uffle/build/cli.bundled.js:163793:9at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:160353:16at replenish (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:160873:25)at iterateeCallback (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:160863:17)at /usr/local/lib/node_modu

6、les/truffle/build/cli.bundled.js:160838:16导致上面异常的原因为是因为 truffle.js 里面未配置链接合约发布的环境地址,找到对应的truffle.js 文件,修改代码为类似如下配置即可解决问题:module.exports = networks: development: host: localhost,port: 8545,network_id: * / 匹配任何 network id;4. 编译 truffle compile5. 测试truffle test6. 交互truffle console6 Sample1. 创建项目mkdir H

7、elloWorldcd HelloWorldtruffle init目录如下:con tracts migrati ons test truffle-con fig.js truffle.js2. 编写代码在con tracts目录下vim HelloWorld.sol内容如下:pragma solidity A0.4.4;con tract HelloWorld fun cti on sayHello() returns (stri ng)return (Hello World);3. 编译:truffle compile4. 修改部署文件truffle.js,内容如下:module.exports = / See / to customize your Truffle con figurati on!n etworks: developme nt: host:localhost,port:8545,network_id: *;5. 在另一个终端启动testrpctestrpc6. 部署 :truffle

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论