Truffle
This section covers how to create and deploy Smart Contracts using Truffle.
You can install Truffle using npm, the Node package manager. Please refer to the following link for instructions on installing npm. https://www.npmjs.com/
If Truffle is intalled, use 'truffle init' command to initialize.
If you execute 'truffle init', 'Truffle project' is created. The generated Truffle project consists of build/contracts, contracts, migrations, tests, and truffle-config.js.
build/contracts : save the result (abi, bitecode) of the compiled contract written in solidity
contract : smart contract solidity files
migrations : deploy code(js format)
test : test code(js format)
truffle-config.js : solidity compiler version setting, network setting and others` configuration
Use the 'truffle create contract' command to create a simple smart contract template.
Apply the 'Greater.sol' that you created earlier on this template.
To compile and deploy the 'Greater.sol' smart contract, you have to change the 'Truffle-config.js' file.
You need to add HDWalletProvider and privKeys in the 'Truffle-config.js' file to set up the account that you use for deployment. Private keys can be imported after you create an account through the Web Wallet or Metamask.
To use the WEMIX3.0 Testnet, add the network settings as show below.
Set the version of the Solidity Compiler you want to use. The current latest version is 0.8.x, and the exmaple uses version 0.8.11. If it is installed directly on the operating system that uses the complier, you can annotate the docker settings in the same way as the initial settings. To install it by using docker, you need to set 'docker:true' as show below and docker must be installed. If you use the optimizer, you can turn off the annotation and set the appropriate settings.
After completing the configuration of the truffle-config.js file, you can execute a smart contract compilation. Running the truffle compile <file name> in the truffle project folder will compile the solidity file you specified as a target. The complied solidity contract are stored in the build/contracts folder in the format, <contract name>.json.
To deploy the compiled smart contract on the blockchain, you need to write the script shown below and save it as 1_deploy_contracts.js.
You can deploy smart contracts individually by loading the smart contracts that you want to deploy with artifacts.require (<artifacts file name stored in build/contacts>), and executing deployer.deploy(contract_artifacts,{constructor arguments}).
The deployed script can be executed with the truffle migrate <file name> above. If you don`t use <file name>, it is performed in the numerical order used in the script name.
The result of the deployment in the WEMIX3.0 Testnet is as follows. For deployment, you must have WEMIX in the account that you want to use for deployment. You can get WEMIX you need from Testnet Faucet.
You can test the deployed smart contract using the javascript file as follows.
contract : test target contract
describe : test case collection
it : each test case
When the test code is complete, save the test file as <testName.test.js> format in the test folder and execute the truffle test <testName.test.js> to perform the test.