Truffle 部署合約 truffle migrate

2020-10-16 12:00:57

部署合約 truffle migrate

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