A solidity project which demonstrates CRUD functions in a solidity smartcontract and how to secure it using RBAC contract methods.
-
Setup docker-ce.
-
Install Latest stable version of Node.js.
-
Optional: Install Visual Studio Code and then install these plugins:
-
Optional: Install yarn if you prefer other alternative of Node.js package manager than Npm.
-
Clone this repository in your local machine, by running
git clone https://github.com/WendySanarwanto/tron-solidity-basic-crud.git
command, on your terminal window. -
Change current directory into the cloned repository's root directory.
-
Install the project's NPM dependencies by running either one of these commands:
npm i
oryarn
, in your terminal. -
Start Tron local development node by running
npm run startnode
command in your terminal. -
Display the node's startup log messages through running
docker logs -f tron
command. Lookup, block, copy or note one or more Account address(es) and their Private Key(s). -
Open the
tronbox.js
file, lookup forlocaldev
property, and then replace the value offrom
property with one of Account address you noted in prior step, also replace the value ofprivateKey
property with the selected Account address'es Private Key. -
Run
npm run cdtl
command to compile all.sol
files, deploy them into the local fullnode and then execute the test, at once. Confirm that there are no errors and all tests are passed.
-
Open your browser tab and browse to Tronscan page.
-
Click SIGN IN link on top-right of the page then followed by clicking IMPORT A WALLET dropped menu item.
-
On the shown modal dialog, click CREATE WALLET button.
-
Follow instructions on next page and ensure that you make notes both the Public & Private keys of the created account.
-
On your browser tab, browse to TRX's Fauchet page.
-
Copy & Paste the Public address of the created dev/test account into
Test wallet address
textbox input and click SUBMIT button. Notice that 10000 TRX is sent into the account. -
Repeat this step until the account has at least 200k TRX or higher.
-
Browse to Shasta Tronscan, sign in by using the Dev/Test account and freeze all the received TRX Test Coins where 50% of the total TRX is frozen to get Bandwidth and the other 50% is frozen to get Energy.
-
Create a new file in the root directory of this repository, and name it as .env.
-
Open the .env file and add this line:
SHASTA_PK=<private key of the test/dev account>
. Example:SHASTA_PK=a73b387e99b838c3d0e4635b6b7d2358b0526f731d066d9db5a504a3c2b929aa
-
Back to terminal window and run
npm run compile
command to compile all smartcontract.sol
files. -
Run
npm run deployshasta
command to deploy (migrate) the compiled contracts to Shasta testnet. Confirm that migration process is finished successfully. Make note the deployed Inventory smartcontract's public address.
-
Edit the .env file and add this line:
SHASTA_INVENTORY_SC=<Deployed Inventory contract's address, noted in prior step>
. -
Add this line in the .env file:
CURRENT_NET=shasta
to ensure that we are going to run the test against the contracts deployed on Shasta test net. Example of current .env file:SHASTA_PK=a73b387e99b838c3d0e4635b6b7d2358b0526f731d066d9db5a504a3c2b929aa SHASTA_INVENTORY_SC=TCrcAbH3Umf6yGoDXtZBuNEjFJ9Qy5NkuC CURRENT_NET=shasta
-
On terminal, run
npm run specs
for starting the integration tests. Confirm that all tests are passed.
-
Edit .env file and add this line:
MAIN_PK=<Private key of your main Tron's account>
. -
Back to terminal window Back to terminal window and run
npm run deploymain
command to deploy (migrate) the compiled contracts to the Main net. Confirm that migration process is finished successfully. Make note the deployed Inventory smartcontract's public address.
-
Edit the .env file and add this line:
MAIN_INVENTORY_SC=<Deployed Inventory contract's address, noted in prior step>
. -
Change
CURRENT_NET
param fromshasta
tomainnet
. Example of current .env file:MAIN_PK=bedbbc9724de3f33e92c188c77210e4bf0503c66a0c6366ccdab7459668d067d MAIN_INVENTORY_SC=TT7bwZuV3ohc9OnMdQPkvQY3PgEzCkLo1I SHASTA_INVENTORY_SC= SHASTA_PK=a73b387e99b838c3d0e4635b6b7d2358b0526f731d066d9db5a504a3c2b929aa SHASTA_INVENTORY_SC=TCrcAbH3Umf6yGoDXtZBuNEjFJ9Qy5NkuC CURRENT_NET=mainnet
-
Ensure that all of your TRX in your main account are freezed and there are enough available Bandwidth & Energy (roughly 200k-300k energy).
-
On terminal, run
npm run specs
for starting the integration tests. Confirm that all tests are passed.
Note
if you have unfreezed TRX and insufficient Energy and or Bandwidth, your TRX could be deducted either after you've deployed the contracts or when running the integration tests. Also, some or all integration tests may be failing if you have not enough Bandwidth & Energy or TRX to burn.
-
Implement functions which returns all data and also support: Pagination & Field's filtering, in the CRUD Smartcontract.
-
Create additional Unit Tests and Integration Tests which test unauthorised access.
-
Refactor Admin.sol contract to use RBAC (Role-Based-Access-Control) feature, taken from Open Zeppelin's RBAC contracts.
-
Create ES6 Helper method(s) or a class that can be used to map Product tupple into JSON object, and use it to replace several lines in the test file.
-
Design & Implement a new smartcontract which acts as Manager & Factory of the CRUD smartcontract.
-
Add/apply solidity Best practices & Patterns on existing smartcontracts.
-
Create the Web SPA clients in ReactJS, Angular and Vue.JS.
-
Deploy the Web SPA client into IPFS.