Linux, or Mac OS X
Installation permissions issue
If the command in the shell fails due to a permission issue, please follow this command to install again: sudo npm install -g tronbox --unsafe-perm=true --allow-root --save-dev grunt If you still have permission issues, you can try to use nvm to manage nmp and node and install again.
**Tronbox npm Package Security Validation** Prepare, you need to install the npm pkgsign for verifying.
First, get the version of tronbox dist.tarball
Second, get the tarball
Finally, verify the tarball
The public key address used for signing is [here](🔗).
## Initialize a Tron-Box Project
Enter the following command under an empty folder
|./contract||The directory storing all smart contract files.|
|./test||The directory storing all test scripts for testing the smart contract.|
|./tronbox.js||The configuration file of the project. Declare your Full Node address and Event Server in this file.|
## Basic Commands
|tronbox compile||Compiles all the smart contracts. The compiled result is stored into ./build/contracts. This command only compiles files that have been modified since the last compile.|
|tronbox compile --compile-all||Re-compiles all the smart contracts.|
|tronbox migrate||Deploys the contract. This command only migrates changes since the last successful migration.|
|tronbox migrate --reset||Re-migrates all the smart contracts.|
|tronbox test [test_script_path]||Runs all test scripts. Test file name definition is optional. It also can be run with --reset flag.|
|tronbox console||The console supports the `|
# Smart Contract Deployment using Tronbox
To deploy a smart contract using a tronbox, you need to write a smart contract file, compile the smart contract, and finally migrate and deploy the smart contract. After that you can then use the script to test.
**Smart Contract Development**
All smart contract files need to be placed in the `
./contracts` directory. By default, there will be a contract file with a suffix of `
.sol`. But if you need to write a smart contract, you need to create a new `
Tronbox requires the smart contract name to be the same as the file name. For example, if the file name is `
Test.sol`, we can write the contract as follows:
**Configuring migration scripts**
Configuring migrations/2_deploy_contracts.js as follows:
The deploy function in this file also supports the contract constructor arguments.
**Configuring compilation and deployment parameters**
The tronbox.js file holds configurations the contract will deploy to. To specify the network, use --network _NETWORK_NAME_ when migrating or testing.
**Note**: Solidity Support
To set up a specific compiler version, using the `
networks.compilers.solc.version` property. For example:
Solidity compiler versions supported by TronBox, please refer to [TronBox Github](🔗).
**Compiling smart contract**
To compile the contract, use:
By default, tronbox compiler only compiles modified contracts since last compile, to reduce unnecessary compiling. If you wish to compile the entire file, you can use `
The compile output is in `
./build/contracts` directory. If the directory doesn't exist, it will be auto-generated.
Migrations` contract to be recorded on the blockchain. Below is a detailed instruction.
To initiate the migration, use the following command:
This command will initiate all migration scripts within the `
migration` directory. If your previous migration was successful, `
tronbox migrate` will initiate a new migration and use the `
development` network by default.
If there is no new migration script, this command will have no operation. Instead, you can use --reset to re-deploy. You can also use --network _NETWORK_NAME_ to specify a network. Eg. `
tronbox migrate --reset --network production`
The testing scripts are in the `
./tests` directory. TronBox will ignore all other extensions except for .js, .es, .es6, and .jsx
Below is an example testing script for test.js:
Running Testing Script
**Example Dapp** It can be obtained by the following command. It can also be found at <a href="https://github.com/sullof/metacoin-box" target="_blank">here</a>.