Setup the development environment for PlatON network smart contract

Language
PlatON test net currently supports both WASM and EVM smart contract virtual machine platform, for WASM platform, the smart contract can develop by C++, and for EMV it will be developed by Solidity.
EVM compatibility
PlatON currently supports EVM smart contract, it’s directly compatible with Etherum EVM smart contract, the only changes that need to made probably will change the unit and the address to PlatON and LAT unit and address.
Things to know before start
Solidity
On EVM you can program by Solidity, so it will absolutely necessary to know how to coding in Solidity. The latest version of Solidity that PlatON currently support is 0.5.13 base on the documents, so make sure to use the syntax that compatible with this version of solidity.
For more information about solidity, you can refer to the docs here,
- Solidity 0.5.13 docs: https://docs.soliditylang.org/en/v0.5.13/
- Wiki: https://en.wikipedia.org/wiki/Solidity

Gas mechanism
To avoid the infinity loop and exponential exploration, PlatON keeps using ETH’s gas mechanism. PlatON will weight the cost of the resources for every transition. User can also set a gas price to control the transaction fee.
Cost of deployment
Cost depends on the binary size of the smart contract, also related to the variable size in the contract. The cost can easily be calculated by the formula:
cost = gas * gas_price
Gas is proportional to the contract code size and variables size, so for the purpose to spend less gas for deployment, what we should be careful about is to reduce the size of both the code and the storage our contract will use.
Setup the DEV environment
Prerequisite
Nod.js: The installation instruction is easy to follow on Node.js website, just refer to this link.
Install Truffle
Truffle is a world-class smart contract development environment and testing framework, it helps to make the journey extremely easy for the developer. For sure we will use it to accelerate our development, and we will use the version provided by PlatON. The specific version for PlatON is already on npm registry so you can simply just install it with npm:
npm install -g platon-truffle
Once installed you can see this when type platon-truffle
in your terminal
PlatON Truffle v0.13.0 - a development framework for PlatON
Usage: platon-truffle <command> [options]
Commands:
compile Compile contract source files
config Set user-level configuration options
console Run a console with contract abstractions and commands available
deploy (alias for migrate)
exec Execute a JS module within this Truffle environment
help List all commands or provide information about a specific command
init Initialize new and empty PlatON project
migrate Run migrations to deploy contracts
networks Show addresses for deployed contracts on each network
obtain Fetch and cache a specified compiler
opcode Print the compiled opcodes for a given contract
test Run JavaScript and Solidity tests
unbox Download a Truffle Box, a pre-built Truffle project
version Show version number and exit
If you can see this then it’s installed successfully.
Initialize the project
Now let’s create a folder, we can call it platon-playground
.
Init the project is very simple, we can just get into the folder and run platon-truffle init
.
If you see the following then you have your project initialled successfully:
✔ Preparing to download
✔ Downloading
✔ Cleaning up temporary files
✔ Setting up box
Unbox successful. Sweet!
Commands:
Compile: truffle compile
Migrate: truffle migrate
Test contracts: truffle test
The project will have the following structure.
.
├── contracts
│ └── Migrations.sol
├── migrations
│ └── 1_initial_migration.js
├── test
└── truffle-config.js
What’s Next
Now we have the project initialized, you can see that now you can compile, migrate and test your code with the truffle command tool. Regardless of the wrong output of those commands, instead of use truffle compile/migrate/test
, use platon-truffle compile/migrate/test
instead in the future.
After this point we can start to do some coding, we will talk about coding a smart contract from the next story.
PlatON Community Links
With any question or maybe want to meet with other developers of PlatON, join PlatON community by these links:
Discord: https://discord.gg/MudQ957W
Twitter: https://twitter.com/PlatON_Network
Telegram: https://t.me/PlatONNetwork