智能合约solidity项目部署流程

solidity项目部署流程

开发环境:vscode
参考:Solidity的Truffle框架实战(手把手)

1. 安装truffle

$ npm install truffle

2.创建项目

$ mkdir solidityTest
$ cd fomo3dTest
$ truffle install

如果项目已经存在,需在项目内执行npm install

修改truffle.js

module.exports = {
  // See 
  // to customize your Truffle configuration!
  networks: {
    development: {
      host: "127.0.0.1",
      port: 8545,
      network_id: "*" // 匹配任何network id
    }
  }
};

3. 安装ganache-cli,web3

$ npm install ganache-cli
$ npm install web3

4.编译

$ truffle compile

5.启动客户端

$ ganache-cli

6.部署合约

$ truffle migrate
$ truffle console
truffle(development)> 
...
truffle(development)> .exit //退出

7.当前可用来测试例子

参考:以太坊开发框架truffle入门指南-01


truffle(development)> Greeter.hasNetwork()
truffle(development)> let contract;
truffle(development)> Greeter.deployed().then( instance => contract = instance );
truffle(development)> contract.setGreeting("hello");
truffle(development)> contract.greet()

8.测试

参考:【区块链】Truffle 部署和测试

注意:测试和部署前,先启动服务器

源码:
https://github.com/xiaoyifan6/solidityExample

你可能感兴趣的:(智能合约solidity项目部署流程)