您现在的位置是:热点 >>正文
如何使用Truffle部署智能合约
热点11268165人已围观
简介...
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 Migrafltions.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; contract&nbse部p;Storage { uint256 storedData; function set(uint256 data) { storedData = data; } functi署智on get() constant returns (uint256) { return storedData; } }
现在转到migrations / 2_deploy_contracts.js并将其修改为如下所示:
var Storage = ar能合tifacts.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项目的选项卡:
$ truffle&n使用bsp;compile $ truffle migrate
这样我们就完成了合同的部署,让我们检查一下我们是否能够调用合同功能。
$ truffle console truffle(development)> Storage.deployed().then(instance => instance.get.call()).then(resuTrlt => 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) '0xc5e2f9c9da4cf9f563c8e59073d5flb6ca9458f112a6dcfc14aaea7c16a99422d4' truffle(development)> Storage.deployed().then(instance => instance.get.call()).then(result => storeData = result) { [String: '99']&e部nbsp;s: 1, e: 1, c: [ 99 ] } truffle(development)> storeData.toString() '99'
目前为止,我们已经成功的部署和测试了Truffle项目合同,
如有任何疑问请在留言区进行留言。
Tags:
相关文章
标签: 星动纪元 具身智能 三星 阿里巴巴
热点云梦级3月5日云梦级消息,具身智能企业星动纪元宣布近日完成10亿元战略轮融资,估值破百亿。本轮融资由三星、高成投资、新加坡电信、友利资本、中金保时捷、中芯聚源、峰和资本(海辰储能)、锡创投、广发乾和、...
【热点】
阅读更多宾大研究揭示:对 AI 越 “粗鲁”,答案越精准!
热点宾夕法尼亚州立大学最近发布了一项引人注目的研究,标题为《Mind Your Tone》,探讨了与大语言模型互动时提问方式对回答准确性的影响。研究显示,使用直白甚至粗鲁的语气进行提问,往往能够获得比礼貌...
【热点】
阅读更多腾讯重磅发布 “混元图像 3.0”,开创多模态图像生成新时代
热点近日,腾讯正式推出并开源了其全新的原生多模态图像生成模型 ——“混元图像3.0(HunyuanImage3.0)”。这一新模型的参数规模达到惊人的80B,标志着在图像生成领域的一次重大技术突破。值得一...
【热点】
阅读更多
热门文章
最新文章
友情链接
- 标签: 康师傅
- https://www.vocabulary.com/dictionary/谷歌霸屏软件【tg:seogoogle987】,ol5
- https://www.tarleton.edu/news/search/谷歌霸屏软件【tg:seogoogle987】,vAL
- https://www.woorden.org/spreekwoord.php?woord=谷歌霸屏软件【tg:seogoogle987】,V90
- https://wwwcp.umes.edu/search/谷歌霸屏软件【tg:seogoogle987】,r4o
- https://www.teamlab.art/fr/?submit=谷歌霸屏软件【tg:seogoogle987】,Xuu
- https://www.whirlpool.com.hk/chinese/catalogsearch/result?cat=30&q=谷歌霸屏软件【tg:seogoogle987】,gg3
- https://www.jusoen.com/addreng.asp?p1=谷歌霸屏软件【tg:seogoogle987】acH
- https://www.nyif.com/catalogsearch/result/index/?f=sarbanesoxleyU&index=me_cms_pe&lit=20&mode=list&p=1&q=谷歌霸屏软件【tg:seogoogle987】,4W3
- https://www.sic-info.org/?s=谷歌霸屏软件【tg:seogoogle987】,OmV
- https://www.metalmensales.com/?action=QUERY&s=谷歌霸屏软件【tg:seogoogle987】,7u5
- https://www.youtube.com/results?search_query=谷歌霸屏软件【tg:seogoogle987】,Edd
- https://www.maigoo.com/search/?block=&q=谷歌霸屏软件【tg:seogoogle987】,P01
- https://www.remit.co.jp/id/?s=谷歌霸屏软件【tg:seogoogle987】,hUN
- https://www.lindseymedicalsupply.com/search/谷歌霸屏软件【tg:seogoogle987】,h2u
- https://www.safetv.go.kr/base/search/view?searchWord=谷歌霸屏软件【tg:seogoogle987】SVL
- https://www.seforall.org/search?keywords=谷歌霸屏软件【tg:seogoogle987】,PCO
- https://www.unclefossil.com/search/谷歌霸屏软件【tg:seogoogle987】gad_source=1&gclid=Cj0KCQjw_-GxBhC1ARIsADGgDjsNKplUXa2F6YGlHBK2sHDQ88cgsJBb05DyO99TV9jNq_cT0kGMqyQaAgHQEALw_wcB
- https://www.lauben.com/de/?s=谷歌霸屏软件【tg:seogoogle987】,J8v
- https://www.stormberg.com/no/search?q=谷歌霸屏软件【tg:seogoogle987】,44w
- https://5gaa.org/?token=6e2l7hjt2i26gzgctgwdrv7v0j6nxorq&s=谷歌霸屏软件【tg:seogoogle987】umW
- https://yscc1986.net/search/谷歌霸屏软件【tg:seogoogle987】cPv
- https://www.mintos.org/?s=谷歌霸屏软件【tg:seogoogle987】,sKW
- https://www.remit.co.jp/vi/?s=谷歌霸屏软件【tg:seogoogle987】oYl
- https://www.roberthalf.com/us/en/jobs/all/谷歌霸屏软件【tg:seogoogle987】qNd
- https://www.ucycle.com/search/=谷歌霸屏软件【tg:seogoogle987】,Za2
- https://www.unclefossil.com/search/谷歌霸屏软件【tg:seogoogle987】,Ziu
- https://www.jusoen.com/addreng.asp?p1=谷歌霸屏软件【tg:seogoogle987】EIZ
- https://www.ushmm.org/search/results.php?q=谷歌霸屏软件【tg:seogoogle987】,REN
- https://www.usslexington.com/?action=QUERY&s=谷歌霸屏软件【tg:seogoogle987】,zJt
- https://www.xvideos.com/tags/谷歌霸屏软件【tg:seogoogle987】,IEt
- https://www.nytimes.com/search?dropmab=true&query=谷歌霸屏软件【tg:seogoogle987】,c4P
- https://www.xbiao.com/search/index?tpf&wd=谷歌霸屏软件【tg:seogoogle987】,3hA
- https://www.smarty.net/search?q=谷歌霸屏软件【tg:seogoogle987】,J5j
- https://www.ushmm.org/search/results/?ID=8s0587Oi8UTv74zPPM4fuhwjNpe2hsEE&q=谷歌霸屏软件【tg:seogoogle987】,nPg
- https://www.vfw.org/search-results?q=谷歌霸屏软件【tg:seogoogle987】,cUC
- https://www.teacherspayteachers.com/Browse/Price-Range/Free/Search:Western International University Physics degree=谷歌霸屏软件【tg:seogoogle987】,4p1
- https://www.skicheck.at/en/?action=CHECK&s=谷歌霸屏软件【tg:seogoogle987】,Lwc
- https://www.tombow.com/en/search/谷歌霸屏软件【tg:seogoogle987】,XjV
- https://www.impactpool.org/search/?type=79&q=谷歌霸屏软件【tg:seogoogle987】Oid
- https://www.remit.co.jp/en/?s=谷歌霸屏软件【tg:seogoogle987】,vXi
- https://www.youthforum.org/search-results?cx=4f5236218ab5e8ef9&ie=UTF-8&q=谷歌霸屏软件【tg:seogoogle987】,NsW
- https://www.pixiv.net/tags/谷歌霸屏软件【tg:seogoogle987】,Aiv
- https://www.supersauna.de/catalogsearch/result/?q=谷歌霸屏软件【tg:seogoogle987】,YKx
- https://www.wheels24.gr/?action=CHECK&s=谷歌霸屏软件【tg:seogoogle987】,61q
- https://www.flickr.com/photos/tags/谷歌霸屏软件【tg:seogoogle987】AJv
- https://www.partilerdunyasi.com/index.php?route=product/search&tag=谷歌霸屏软件【tg:seogoogle987】,UZc
- https://www.randjleather.co.uk/index.php?route=product/search&tag=谷歌霸屏软件【tg:seogoogle987】,ON7
- https://m.shoppinghow.kakao.com/m/search/q/谷歌霸屏软件【tg:seogoogle987】Dgj
- https://www.sbaad.no/?s=谷歌霸屏软件【tg:seogoogle987】,wJ5
- https://www.lechzuers.com/de/search?cat=163&q=谷歌霸屏软件【tg:seogoogle987】,den