1. Advanced level of Solidity programming language development framework 1. Configuration file

Location

your config file is truffle.js. located in the root directory of the project. This file is a Javascript file that supports executing code to create a configuration. It must export an object to represent the project configuration, as in the example below.

Namespace conflict under WINDOWS

When using the Windows command line, the default configuration file name truffleconflicts with . In this case, we recommend using Windows Power Shell or Git BASH. You can also rename the config file truffle-config.jsto avoid conflicts.

example

module.exports = {
  build: {
    "index.html": "index.html",
    "app.js": [
      "javascripts/app.js"
    ],
    "app.css": [
      "stylesheets/app.css"
    ],
    "images/": "images/"
  },
  rpc: {
    host: "localhost",
    port: 8545
  }
};

The default profile is already configured, buildand rpc. These default and non-default options are detailed later.

Options

BUILD

This is the front-end build configuration. The default builder is invoked by default, described in the build section above. But you can also customize the build process, see the Advanced Build Process chapter to learn more.

example:

build: {
  "index.html": "index.html",
  "app.js": [
    "javascripts/app.js"
  ],
  "app.css": [
    "stylesheets/app.css"
  ],
  "images/": "images/"
}

NETWORKS

Specifies which network to use when migrating. When compiling or running the port on a specific network, the contract is cached for subsequent use. When your contract abstraction layer detects that you are connected to a network, it will use the original cached contract on the network to simplify the deployment process. Networks are identified by RPC calls in net_versionEthereum.

The following networksobjects use a network name as a configuration key, and the value defines its network parameters. networksThe corresponding option is not required, but if once specified, each network must define a corresponding network_id. If you want to specify a default network, you can do so by netword_idmarking the value of default, which will be used when no other network is matched. It should be noted that there should be only one defaultnetwork in the entire configuration. Generally speaking, the default network is mainly used for development, configuration, contracts and other data that do not need to be stored for a long time, and the network ID will also change frequently due to the restart of TestRPC.

The network name is used when the user interface is called, and it is used in the migration as follows:

$ truffle migrate --network live

你还可以选择性的指定rpc的配置信息。下面是一个示例:

networks: {
  "live": {
    network_id: 1, // Ethereum public network
    // optional config values
    // host - defaults to "localhost"
    // port - defaults to 8545
    // gas
    // gasPrice
    // from - default address to use for any transaction Truffle makes during migrations
  },
  "morden": {
    network_id: 2,        // Official Ethereum test network
    host: "178.25.19.88", // Random IP for example purposes (do not use)
    port: 80
  },
  "staging": {
    network_id: 1337 // custom private network
    // use default rpc settings
  },
  "development": {
    network_id: "default"
  }
}

RPC

关于如何连接到以太坊客户端的一些细节。hostport是需要,另外还需要一些其它的。

  • host:指向以太坊客户端的地址。本机开发时,一般为localhost
  • port:以太坊客户端接收请求的端口,默认是8545
  • gas:部署时的Gas限制,默认是4712388
  • gasPrice:部署时的Gas价格。默认是100000000000(100 Shannon)
  • from:移植时使用的源地址。如果没有指定,默认是你的以太坊客户端第一个可用帐户。

示例:

rpc: {
  host: "localhost",
  port: 8545
}

MOCHA

MochaJS测试框架的配置选项,详细参考documentation

示例:

mocha: {
  useColors: true
}
文章来源:学什么技术好网站编译

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325809794&siteId=291194637