- Creating a project
- Choosing an Ethereum client
- Compiling contracts
- Running migrations
- Testing your contracts
- Writing tests in Solidity
- Interacting with your contracts
- Package management via EthPM
- Package management via NPM
- Debugging your contracts
- Using the console
- Writing external scripts
- Using the build pipeline
- Contact the developers
All of your contracts are located in the
./contracts directory. By default you're given an example Solidity contract file and an example Solidity library file, both with filenames ending in
.sol. Although a Solidity library is different than a contract, for documentation purposes we're going to lump these into the same word, "contracts".
To compile your contracts, simply run:
$ truffle compile
Truffle will compile only the contracts that have been changed since the last compile, to reduce any unnecessary compilation. If you'd like to override this behavior, run the above command with the
Artifacts of your compilation will be placed in the
./build/contracts directory, relative to your project. This directory will be created if it does not exist. These artifacts are integral to the inner workings of Truffle, and they play an important part in the successful deployment of your application. You should not edit these files by hand as they'll be overwritten by contract compilation and deployment.
You can declare contract dependencies using Solidity's import command. Truffle will compile contracts in the correct order and ensure all dependencies are sent to the compiler. Dependencies can be specified in two ways:
To import contracts from a separate file, simply write the following command, where
AnotherContract.sol is relative to the current contract being written. This will make all contracts within
AnotherContract.sol available to the current source file.
Note that Solidity allows other import syntaxes as well. See their import documentation for more information.
Truffle supports dependencies installed via NPM as well as EthPM. To import contracts from a dependency, use the following syntax, where
somepackage represents a package installed via NPM or EthPM, and
/SomeContract.sol represents a path to a Solidity source file provided by that package.
Note that Truffle will search installed packages from EthPM first before searching for packages installed from NPM, so in the rare case of a naming conflict the package installed via EthPM will be used.