How to use
truffle [command] [options]
Order
build
To build a development version of the app, create the .build
directory.
truffle build
optional parameter
- --dist: Create a distributable version of the app. Only available when using the default constructor.
console
Runs a console with an initialized, ready-to-use contract object.
truffle console
Once the console is up, you can use your contract via the command line, just like in the code. Also all Truffle commands listed here can be used in the console.
Optional parameters:
- --network name: specify the network to use
- --verbose-rpc: Output details of Truffle and RPC communication.
See the other 9. Console chapters for more information.
compile
Smart compiling of your contracts will only compile contracts that have been modified since the last compilation, unless a forced refresh is specified otherwise.
truffle compile
Optional parameters:
- --compile-all: Force compilation of all contracts.
- --network name: Specify the network to use, and save the compiled results to the specified network.
create:contract
The utility method uses scaffolding to create a new contract. The name needs to conform to camelCase:
$ truffle create:contract MyContract
create:test
Tool method, which uses scaffolding to create a new test method. The name needs to conform to camelCase.
$ truffle create:test MyTest
migrate
Run the migration of the project. See 移植
the relevant chapters for details.
truffle migrate
Optional parameters:
- --reset: Run all migrations from scratch.
- --network name: Specify the network to use and save the compiled data to that network.
- --to number: Migrate the version from the current version to the version specified by the serial number.
- --compile-all: Force compilation of all contracts
- --verbose-rpc: Print a detailed log of Truffle's interaction with RPC.
exec
Execute a Javascript file in the context of Truffle. The environment contains, web3, the default provider based on network settings, and your contract object as a global object. This Javascript file needs to export a function so that Truffle can execute. See 10. External Scripts to learn more.
$ truffle exec /path/to/my/script.js
Optional parameters:
- --network name: name: Specifies the network to use and save the compiled data to that network.
init
Initialize a brand new APP, a brand new project in the current directory. It will come with default contracts and front-end configuration.
$ truffle init
list
List all available commands, --help
equivalent to .
truffle list
serve
Provides services corresponding to http://localhost:8080
compiled apps, and automatically builds and deploys them when needed. Similar truffle watch
to, the difference is that the web server function is added here.
truffle serve
Optional parameters:
- -p port: Specify the port of the http service. The default is 8080.
- --network name: name: Specifies the network to use and save the compiled data to that network.
test
Run all ./test
test cases in the directory. Or optionally run a single test file.
$ truffle test [/path/to/test/file]
Optional parameters:
- --network name: Specify the network to use and save the compiled data to that network.
- --compile-all: Force compilation of all contracts
- --verbose-rpc: Print a detailed log of Truffle's interaction with RPC.
version
Print the version number and exit.
truffle version
watch
Watch contracts, apps, and configuration file changes, and automatically build apps when needed.
truffle watch
Article translation:
What technology is good to
learn