How to do it...

  1. Smart contracts for a Truffle project are located in the./contracts directory. Since solidity is the language of choice for smart contracts, the source code files will have the .sol extension.

  1. There may be one or more contract files in a project. Use the compile command to compile the smart contracts present in the directory. Make sure that you are at the root of the project:
truffle compile
  1. If you are running the command for the first time, then it will compile all the contracts present in the folder. You can see the status on your console, as shown in the following screenshot:
  1. For subsequent runs, only the contracts that have been modified since the last compile will be compiled by Truffle. If you want to compile all contracts again, use the --all option:
truffle compile --all
  1. Compiler output is saved in individual JSON files. It is available in the ./build/contracts directory. The output file may have the following artifacts:

{ 
"contractName": "",
"abi": [],
"bytecode": "",
"deployedBytecode": "",
"sourceMap": "",
"deployedSourceMap": "",
"source": "",
"sourcePath": "",
"ast": {},
"legacyAST": {},
"compiler": {
"name": "",
"version": ""
},
"networks": {},
"schemaVersion": "",
"updatedAt": ""
}
  1. It is recommended not to edit these files as they will be overwritten by subsequent compilation and deployment processes.

  2. Multiple contracts can be linked together for compilation. This is handled in solidity, and you can use the import statement to do the same:
import "<path_to_the_contract.sol>";
  1. Truffle supports package managers such as EthPM and npm, and you can import downloaded contracts by referring to the package as follows:
import "packageName/contract.sol";

Here, packageName refers to the downloaded package and contract.sol refers to the smart contract source.

  1. Truffle gives priority to the packages downloaded through EthPM and then to npm. If there is a naming conflict, Truffle will consider the package downloaded through EthPM.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.158.36