您现在的位置是:热点 >>正文
如何使用Truffle部署智能合约
热点21581人已围观
简介...
Truffle是一个开发环境(提供用于编译,部署,测试和构建的命令行工具),框架(提供各种程序包以使其易于编写测试,部署代码,构建客户端等)和资产管道(发布软件包并使用其他人发布的软件包来构建基于以太坊的DApp。
使用Truffle,您可以获得:
内置的智能合约编译,链接,部署和二进制管理。 与Mocha和Chai进行自动化合同测试。 可配置的构建管道,支持自定义构建过程。 可编写脚本的部署和迁移框架。 网络管理,用于部署到许多公共和专用网络。 用于直接合同通信的交互式控制台。 在开发过程中如何立即重建资产。 外部脚本运行程序,在Truffle环境中执行脚本。
要使用大多数Truffle命令,您需要在现有的Truffle项目上运行它们。因此,第一步是创建一个Truffle项目,让我们从安装Truffle开始:
$ npm install -g truffle
确保已安装:
$ truffle Truffle v3.2.1 - a development 使用framework for Ethereum Usage: truffle [options] Commands: init Initialize new Ethereum project with example contracts and&nbsTrp;tests ...
然后创建项目:
$ mkdir storage_smart_contract_example $ cd storage_smart_contract_example $ truffle init
在这里,您可以运行Truffle编译,Truffle迁移和Truffle测试来编译您的合同,将这些合同部署到网络中,并运行其关uf联的单元测试。
Truffle与本地开发区块链服务器捆绑在一起,当您调用上述命令时,该服务器会自动启动。如果您想配置更高级的开发环境,我们建议您通过在命令行上运行npm install -g ganache-cli来单独安装区块链服务器。
ganache-cli:Truffle的区块链服务器的命令行版本。
ganache:服务器的GUI,显示您的交易历史记录和链状态。
Truffle项目的结构
您创建的Truffle文件夹如下所示:
1.合同
ConvertLib.sol MetaCoin.sol Migflrations.so
2.迁移
1_initial_migration.js 2_deploy_contracts.js
3.测试
TestMetacoin.sol metacoin.js
4. truffle-config.js
5. truffle.js
现在进一步编写代码,您将看到Truffle为我们创建了文件结构。转到合同文件夹并创建Storage.sol文件,然后在其中写入智能合同的代码。
pragma solidity ^0.4.8; contrace部t Storage { uint256 storedData; function set(uint256 data) { storedData = data; } f署智unction get() constant returns (uint256) { return storedData; } }
现在转到migrations / 2_deploy_contracts.js并将其修改为如下所示:
var Storage = 能合;artifacts.require("./Storage.sol"); module.exports = function(deployer) { deployer.deploy(Storage); };
现在我们已经有了基本的设置,我们需要将其部署到区块链上,让我们使用testrpc可以很好地完成测试开发目的,在一个单独的选项卡上,如何键入以下命令:
$ npm install -g ethereumjs-testrpc $ testrpc EthereumJS TestRPC v3.0.3 Available Accounts ================== …
然后返回运行Truffle项目的选项卡:
$ tr使用uffle compile $ truffle migrate
这样我们就完成了合同的部署,让我们检查一下我们是否能够调用合同功能。
$ truffle console truffle(development)> Storage.deployed().then(instance => instance.get.call()).theTrn(result => storeData = result) { [String: '0'] s: 1, e: 0, c: [ 0 ] } truffle(development)> storeData.toString() '0' uf;
现在让我们看看是否可以将storeData设置为值99。
truffle(development)> Storage.deployed().then(instance => instance.set.sendTransaction(99)).then(result => newStorageData = result) '0xc5e2f9c9da4cf9f563c8e59073fld5b6ca9458f112a6dcfc14aaea7c16a99422d4' truffle(development)> Storage.deployed().then(instance => instance.get.call()).then(result => storeData = result) { [String: '9e部9'] s: 1, e: 1, c: [ 99 ] } truffle(development)> storeData.toString() '99'
目前为止,我们已经成功的部署和测试了Truffle项目合同,
如有任何疑问请在留言区进行留言。
Tags:
相关文章
云计算核心技术Docker教程:Docker 使用网络端口映射连接
热点在Docker 网络功能之前,您可以使用 Docker 链接功能来允许容器相互发现并将有关一个容器的信息安全地传输到另一个容器。随着 Docker 网络功能的引入,您仍然可以创建链接,但它们在默认br...
【热点】
阅读更多Meta陷入史上最大AI训练数据侵权案!2396部影片非法使用,面临3.59亿美元天价索赔
热点人工智能训练数据的合法性争议终于演化成了一场震撼硅谷的法律风暴。美国加利福尼亚州法院最近受理的一起诉讼案件,将全球科技巨头Meta推到了舆论的风口浪尖。两家成人影片制作公司Strike3和Counte...
【热点】
阅读更多标签: 阿里千问 千问App 春节免单 盒马
热点云梦级2月6日云梦级消息,阿里千问 App 宣布,刚刚,“千问春节 30 亿大免单”活动订单量已超过 1000 万单,这距离活动上线仅 9 个小时。 官方表示,今天,大家对千问 App 说了 3000...
【热点】
阅读更多
热门文章
最新文章
友情链接
- 标签: 康师傅
- https://www.otakuninjahero.com/en/search/谷歌搜索留痕霸屏【tg:seogoogle987】,r4v
- https://www.openstreetmap.org/search?query=谷歌搜索留痕霸屏【tg:seogoogle987】,IIe
- https://www.supersauna.de/catalogsearch/result/?q=谷歌搜索留痕霸屏【tg:seogoogle987】,ZmL
- https://www.ushmm.org/search/results.php?q=谷歌搜索留痕霸屏【tg:seogoogle987】,kYX
- https://www.nuovabai.it/catalogsearch/result/?action=SEARCH&q=谷歌搜索留痕霸屏【tg:seogoogle987】,Jct
- https://www.rea.govt.nz/search?searchterm=谷歌搜索留痕霸屏【tg:seogoogle987】,V4K
- https://www.theaerogroup.net/?cat=28&s=谷歌搜索留痕霸屏【tg:seogoogle987】,Y8V
- https://www.tarleton.edu/?s=谷歌搜索留痕霸屏【tg:seogoogle987】,ZeP
- https://www.teamlab.art/fr/?submit=谷歌搜索留痕霸屏【tg:seogoogle987】,OOM
- https://www.zalora.sg/catalog/?cat=112&q=谷歌搜索留痕霸屏【tg:seogoogle987】,iLp
- https://www.duksung.ac.kr/search/front/Search.jsp?qt=谷歌搜索留痕霸屏【tg:seogoogle987】G77
- https://www.lifesciencesweden.se/search?q=谷歌搜索留痕霸屏【tg:seogoogle987】,Oyg
- https://www.maafushidive.com?collections?vendors?q=谷歌搜索留痕霸屏【tg:seogoogle987】,V2T
- https://www.tombow.com/en/search/谷歌搜索留痕霸屏【tg:seogoogle987】,6Sy
- https://www.oprny.com/search.php?search_query=谷歌搜索留痕霸屏【tg:seogoogle987】,OLp
- https://www.temu.com/search_result.html?search_key=谷歌搜索留痕霸屏【tg:seogoogle987】LgP
- https://www.urmc.rochester.edu/news/search?q=谷歌搜索留痕霸屏【tg:seogoogle987】,gsN
- https://www.randjleather.co.uk/index.php?route=product/search&tag=谷歌搜索留痕霸屏【tg:seogoogle987】,Hqr
- https://www.selfsufficientish.com/main/?s=谷歌搜索留痕霸屏【tg:seogoogle987】,BPp
- https://www.jusoen.com/addreng.asp?p1=谷歌搜索留痕霸屏【tg:seogoogle987】GrS
- https://www.lyrics.com/lyrics/谷歌搜索留痕霸屏【tg:seogoogle987】,YAC
- https://www.whirlpool.com.hk/chinese/catalogsearch/result?cat=30&q=谷歌搜索留痕霸屏【tg:seogoogle987】,gg9
- https://www.kaliastyle.com/catalogsearch/result/?q=GOOGLE谷歌搜索留痕霸屏【tg:seogoogle987】,NdZ
- https://www.thedp.com/page/search?q=谷歌搜索留痕霸屏【tg:seogoogle987】,bph
- https://www.sbaad.no/search/谷歌搜索留痕霸屏【tg:seogoogle987】,TiZ
- https://www.goodreads.com/quotes/tag/谷歌搜索留痕霸屏【tg:seogoogle987】RvR
- https://www.swanagerailway.co.uk/search?q=谷歌搜索留痕霸屏【tg:seogoogle987】,6CY
- https://www.kubb-tool.bfs.admin.ch/en/search?action=CHECK&q=谷歌搜索留痕霸屏【tg:seogoogle987】,yIb
- https://www.vocabulary.com/dictionary/谷歌搜索留痕霸屏【tg:seogoogle987】,xIZ
- https://www.nss.nhs.scot/search?q=谷歌搜索留痕霸屏【tg:seogoogle987】,Zbk
- https://yscc1986.net/search/谷歌搜索留痕霸屏【tg:seogoogle987】82T
- https://www.sonepar.ch/fr/search?q=谷歌搜索留痕霸屏【tg:seogoogle987】,5j3
- https://www.pinkpanda.ro/magazin/ingrijirea-tenului?page=87&q=谷歌搜索留痕霸屏【tg:seogoogle987】,Lp6
- https://www.lneg.pt/?cat=140&s=谷歌搜索留痕霸屏【tg:seogoogle987】,u5q
- https://www.skicheck.at/en/?action=CHECK&s=谷歌搜索留痕霸屏【tg:seogoogle987】,FnH
- https://www.revere.org/search?action=SEARCH&q=谷歌搜索留痕霸屏【tg:seogoogle987】,HnZ
- https://www.parl.ca/legisinfo/fr/projets-de-loi?parlsession=all&view=list&keywords=谷歌搜索留痕霸屏【tg:seogoogle987】,3uU
- https://www.partilerdunyasi.com/index.php?route=product/search&tag=谷歌搜索留痕霸屏【tg:seogoogle987】,zq7
- https://www.remit.co.jp/zh/?s=谷歌搜索留痕霸屏【tg:seogoogle987】,24a
- https://www.searcychamber.com/list/search?AsfnA=DtkTQzs&q=谷歌搜索留痕霸屏【tg:seogoogle987】,WLG
- https://www.teamlab.art/ko/?submit=谷歌搜索留痕霸屏【tg:seogoogle987】,nlx
- https://www.pacific-lifestyle.co.uk/search?sort=alphabetical&term=谷歌搜索留痕霸屏【tg:seogoogle987】,Vi2
- https://5gaa.org/?token=6e2l7hjt2i26gzgctgwdrv7v0j6nxorq&s=谷歌搜索留痕霸屏【tg:seogoogle987】5M1
- https://www.miamiopenmri.com/?action=CHECK&s=谷歌搜索留痕霸屏【tg:seogoogle987】,RZ4
- https://www.roberthalf.com/us/en/jobs/all/谷歌搜索留痕霸屏【tg:seogoogle987】zf5
- https://www.voices.com/talents/search?keywords=谷歌搜索留痕霸屏【tg:seogoogle987】,418
- https://www.vfw.org/search-results?q=谷歌搜索留痕霸屏【tg:seogoogle987】,oL6
- https://www.pixiv.net/tags/谷歌搜索留痕霸屏【tg:seogoogle987】,2Wa
- https://www.ucycle.com/search/=谷歌搜索留痕霸屏【tg:seogoogle987】,VQQ
- https://www.monroecounty.gov/search/?q=谷歌搜索留痕霸屏【tg:seogoogle987】,Ffo