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.
To set up a specific compiler version, use the typical Truffle approach in tronbox.js, using the `
networks.compilers.solc.version` property. For example:
Solidity compiler versions supported by TronBox:
<a href="https://github.com/ethereum/solidity/releases/tag/v0.4.24" target="_blank">**0.4.24**</a>
<a href="https://github.com/ethereum/solidity/releases/tag/v0.4.25" target="_blank">**0.4.25**</a>
<a href="https://github.com/ethereum/solidity/releases/tag/v0.5.4" target="_blank">**0.5.4**</a>
<a href="https://github.com/ethereum/solidity/releases/tag/v0.5.8" target="_blank">**0.5.8**</a>
## 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.
## Contract Deployment
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`
## Trigger Contract
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>.