8. Compilation contract of Solidity programming language development framework

Contract position

All your contracts should be located in the ./contractsdirectory. By default, we provide a contract file and a library file, both .solending with examples. Although library files have certain specificities, they are currently called contracts for simplicity.

Order

To compile your contract, use:

truffle compile

Truffle only compiles files that have been modified since the last compilation by default to reduce unnecessary compilations. If you want to compile all files, you can use --compile-alloptions.

truffle compile --compile-all

convention

Truffle needs to match exactly the contract name and file name defined. For example, if the file name is MyContract.sol, the contract file must be one of the following:

contract MyContract {
  ...
}
// or
library MyContract {
  ...
}

This matching is case-sensitive, which means the case must be the same. It is recommended to capitalize each initial letter, as defined in the code above.

rely

You can declare dependencies by using import . Truffle will compile the contracts in the correct order and automatically link libraries when needed.

build directory

The compiled output is located in the ./build/contractsdirectory. If the directory does not exist it will be created automatically. These compiled files are critical for the Truffle framework to work properly. You should not manually modify these files outside of normal compilation or release.

If you have any questions , please leave a message for criticism and correction.

Guess you like

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