Migrations 直译”迁移“
要运行部署,请运行以下命令
truffle migrate
一个简单的迁移文件,如文件名:4_example_migration.js
文件名以数字为前缀,后缀为描述
var MyContract = artifacts.require("XlbContract");
module.exports = function(deployer) {
// 部署步骤
deployer.deploy(MyContract);
};
E:\workspace\KnowledgeManagement\BlockChain\Solidity\study\truffle>truffle migrate
Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.
Starting migrations...
======================
> Network name: 'development' #需要在truffle-config.js中配置需要连接的链
> Network id: 1600237726213
> Block gas limit: 6721975 (0x6691b7)
1_initial_migration.js
======================
Deploying 'AddressBalance'
--------------------------
> transaction hash: 0x9d7225302d583d2188a7108256de245d7a5096ea1fbd38f906e676896d53a3a8
truffle migrate --network ropsten
部署到测试网络,网络比较慢,可能会出现timeout
E:\workspace\KnowledgeManagement\BlockChain\Solidity\study\truffle>truffle migrate --network ropsten --reset
Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.
Starting migrations...
======================
> Network name: 'ropsten'
> Network id: 3
> Block gas limit: 8000000 (0x7a1200)
1_initial_migration.js
======================
Replacing 'AddressBalance'
--------------------------
> transaction hash: 0x4b5f989eceb43c19c954bbe31132a04ea1f29c01033086d1908d0e2e7f316f36
> Blocks: 2 Seconds: 9
> contract address: 0xbf6AF9B523807E4f7f4831cCF1541cCfAa0830B2
> block number: 8849250
> block timestamp: 1602313584
> account: 0x3946750f99720c8A497b8be804385fB5b9b83820
> balance: 104.935565653509715
> gas used: 172183 (0x2a097)
> gas price: 20 gwei
> value sent: 0 ETH
> total cost: 0.00344366 ETH
Pausing for 2 confirmations...
------------------------------
> confirmation number: 1 (block: 8849251)
> confirmation number: 2 (block: 8849252)
> Saving artifacts
-------------------------------------
> Total cost: 0.00344366 ETH
Summary
=======
> Total deployments: 1
> Final cost: 0.00344366 ETH
E:\workspace\KnowledgeManagement\BlockChain\Solidity\study\truffle>
部署成功之后就可以查到对于的合约
https://ropsten.etherscan.io/address/0xbf6AF9B523807E4f7f4831cCF1541cCfAa0830B2