其他分享
首页 > 其他分享> > 部署智能合约

部署智能合约

作者:互联网

truffle unbox react 下载项目
在这里插入图片描述
修改truffle-config.js

const path = require("path");

module.exports = {
  // See <http://truffleframework.com/docs/advanced/configuration>
  // to customize your Truffle configuration!
  contracts_build_directory: path.join(__dirname, "client/src/contracts"),
  networks: {
    develop: {
      host: 'localhost',
      port: '7545',
      network_id: '*' // Match any network id 
    }
  }
};

进入控制台
在这里插入图片描述
编译智能合约
在这里插入图片描述
迁移到区块链上

truffle(develop)> migrate

Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.



Starting migrations...
======================
> Network name:    'develop'
> Network id:      5777
> Block gas limit: 0x6691b7


1_initial_migration.js
======================

   Deploying 'Migrations'
   ----------------------
   > transaction hash:    0xaa0788f7bd013dec3d999f543c20d6ac5c7d3cf6cf4756b6656f313fecf90034
   > Blocks: 0            Seconds: 0
   > contract address:    0x7bdD98D5f749941a4928af0f8c1A9cC184749A57
   > block number:        1
   > block timestamp:     1580287418
   > account:             0x59e747a0c6315d4ac024FB2dD8a67d14907e19Bf
   > balance:             99.99623034
   > gas used:            188483
   > gas price:           20 gwei
   > value sent:          0 ETH
   > total cost:          0.00376966 ETH


   > Saving migration to chain.
   > Saving artifacts
   -------------------------------------
   > Total cost:          0.00376966 ETH


2_deploy_contracts.js
=====================

   Deploying 'SimpleStorage'
   -------------------------
   > transaction hash:    0x78a01569782ccb26d8463c4431f791f93674c7ace8af55dcf667899b4427d547
   > Blocks: 0            Seconds: 0
   > contract address:    0x6c9F6cA9ed18D2A530bE3C3242d582a42ce3042B
   > block number:        3
   > block timestamp:     1580287419
   > account:             0x59e747a0c6315d4ac024FB2dD8a67d14907e19Bf
   > balance:             99.99324294
   > gas used:            107369
   > gas price:           20 gwei
   > value sent:          0 ETH
   > total cost:          0.00214738 ETH


   > Saving migration to chain.
   > Saving artifacts
   -------------------------------------
   > Total cost:          0.00214738 ETH


Summary
=======
> Total deployments:   2
> Final cost:          0.00591704 ETH

ganache上第一个账户的以太币确实发生了减少
在这里插入图片描述
control+ - +d退出控制台
cd client,然后执行npm run start启动项目

横石拦浪 发布了57 篇原创文章 · 获赞 3 · 访问量 2068 私信 关注

标签:Saving,部署,gas,智能,cost,contracts,ETH,合约,block
来源: https://blog.csdn.net/qq_20786911/article/details/104107610