How to do it...

  1. Install the Truffle package globally using npm. You might want to use the sudo command as follows if you face any permissions issues:
npm install -g truffle
  1. Once the package is installed, you can access it through the command line. Create an empty truffle_project folder for your Truffle project using the following command:
mkdir truffle_project
cd truffle_project
  1. Use the init command to initialize your project with the default contracts and migrations:
truffle init
  1. The preceding command will create a basic template that you can use to start your project. The template will have the following file structure:
    • ./contracts to store your Solidity smart contract files
    • ./tests to store smart contracts and application test scripts
    • ./migrations to store deployment and migration scripts
    • ./truffle.js file to keep the application and network configuration
  2. After creating the contract and related scripts, run the following commands to compile, migrate, and test your Truffle project:

    • truffle compile to compile your smart contracts
    • truffle migrate to run the migration scripts
    • truffle test to run the test cases

Windows users may face issues with running truffle commands from the command prompt. This is because of the truffle.js file present in the root directory. The command precedence property of the command prompt executes the .js file rather than the truffle.cmd executable on the path. To resolve this issue, either call the executable with the .cmd extension (truffle.cmd compile) or use Git bash or PowerShell terminals to run the scripts.

  1. Edit the truffle.js configuration file to change the project configuration and change properties such as network, account, gas, and so on. The following is the basic structure of the file:
module.exports = { 
networks: {
development: {
host: "localhost",
port: 8545,
network_id: "*" // Match any network id
}
}
};
..................Content has been hidden....................

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