2. Advanced Network and APP Deployment of Solidity Programming Language Development Framework

background

Even the smallest projects will deal with at least two or more blockchains, one is the test chain on the development machine, such as EthereumJS TestRPC . The other is for example the network you will eventually deploy, such as the Ethereum network, within your own company. Private chain, etc. Truffle provides a system for managing build and deployment resources across different networks to simplify the final deployment process.

specify a network

Most of the commands provided by Truffle behave differently depending on the specified network, and use the contract and configuration information under the corresponding network. --networkThis can be controlled on the parameter via options.

$ truffle migrate --network live
networks: {
  development: {
    host: "localhost",
    port: 8545,
    network_id: "*" // match any network
  },
  live: {
    host: "178.25.19.88", // Random IP for example purposes (do not use)
    port: 80,
    network_id: 1,        // Ethereum public network
    // optional config values
    // gas
    // gasPrice
    // from - default address to use for any transaction Truffle makes during migrations
  }
}

In the above example, Truffle will livebe ported across the network. If the configuration is as specified in the Example section of the configuration example above, it is ultimately deployed on the Ethereum network.

build resources

As mentioned in the chapter 4. Compiling the contract./build/contracts , the built resources are stored in the directory and .sol.jsexist as such files. When you compile a contract file, or run a port on a network, Truffle will update these .sol.jsfiles with information about the network. When these resources are used later, such as in front-end applications. It will automatically detect the currently used network and automatically use the corresponding contract resources according to the network.

Application deployment

Because the network is automatically detected at runtime, this means you only need to deploy your app or frontend once. When your program runs, it will dynamically detect the currently used network to call appropriate resources, which makes your program very flexible.

For example, if you publish your program to https://www.cfive.ccthe wallet browser, your program will work just fine. If your wallet browser runs on the official network, your dapp will use the contract deployed on the official network, and if it is on the test network, it will use the resources of the test network accordingly. Article editors are collected on what to learn

Guess you like

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