Linux command
truffle 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Initialize project
truffle init
Compile contracts
truffle compile
Run migrations
truffle migrate
Run tests
truffle test
Start console
truffle console
Deploy to network
truffle migrate --network [mainnet]
Start development blockchain
truffle develop
Create a new contract
truffle create contract [ContractName]
Create a new migration
truffle create migration [MigrationName]
Run a specific test
truffle test [test/MyContract.test.js]
Compile with optimizer
truffle compile --all
说明
Truffle is a development framework for Ethereum smart contracts that provides a complete workflow from compilation through deployment and testing. It compiles Solidity contracts into bytecode and ABI artifacts, manages deployment through ordered migration scripts, and supports both JavaScript and Solidity test suites. The built-in development blockchain (truffle develop) provides a local Ethereum environment with instant transactions and pre-funded accounts, eliminating gas costs during development. The interactive console connects to any configured network and allows direct interaction with deployed contracts. Projects are organized with a standard directory structure including contracts, migrations, and test directories. Network configurations in truffle-config.js define deployment targets from local development to public testnets and mainnet.
参数
- init
- Initialize project.
- compile
- Compile contracts.
- migrate
- Deploy contracts.
- test
- Run tests.
- console
- Interactive console.
- develop
- Local blockchain.
- create _TYPE_ _NAME_
- Generate a new contract, migration, or test boilerplate.
- unbox _box_name_
- Download a pre-built Truffle project (Truffle Box).
- networks
- Show addresses of deployed contracts on each network.
- debug _txHash_
- Interactively debug a transaction.
- --network _NAME_
- Target network (defined in truffle-config.js).
- --reset
- Re-run all migrations from the beginning.
- --compile-all
- Recompile all contracts even if unchanged.
- --verbose-rpc
- Log RPC communication with the Ethereum client.
FAQ
What is the truffle command used for?
Truffle is a development framework for Ethereum smart contracts that provides a complete workflow from compilation through deployment and testing. It compiles Solidity contracts into bytecode and ABI artifacts, manages deployment through ordered migration scripts, and supports both JavaScript and Solidity test suites. The built-in development blockchain (truffle develop) provides a local Ethereum environment with instant transactions and pre-funded accounts, eliminating gas costs during development. The interactive console connects to any configured network and allows direct interaction with deployed contracts. Projects are organized with a standard directory structure including contracts, migrations, and test directories. Network configurations in truffle-config.js define deployment targets from local development to public testnets and mainnet.
How do I run a basic truffle example?
Run `truffle init` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does init do in truffle?
Initialize project.