Truffle
Truffle is a powerful tool for contract development assistance.
Environment installation
Node
Refer to Installing Node.jsγ
Truffle
Install Truffle
npm install -g truffleExecute the following commands after installation:
truffle versionInformation displayed similar to the following indicates a successful installation.
Truffle v5.3.3 (core: 5.3.3)
Solidity v0.5.16 (solc-js)
Node v14.16.1
Web3.js v1.3.5Create Project
Create project directory
Use truffle to initialize project
After the project is initialized, the directory structure is as follows:
Edit configuration file
Note: it requires private key to be passed in for Provider, this is the seed phrase for the account you'd like to deploy from. Create a new .secret file in root directory and enter your private key to get started. To export private key from metamask wallet you can go to Account Details, then click button Export Private Key and you will see the private key by enter your password of your account.
Edit Contract
Put the customized contract in the contracts folder and modify the deployment script in the migrations folder
Deploy Contract
Execute deployment commands
Taking the project MetaCoin for instance. Contract codes are as follows:
Output results are as follows:
Interaction
Enter interactive console
Obtain contract abstraction
Initiate a transaction on console
Initiate a call on console
Take the method of calling contract getBalance as an example:
Last updated