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,

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

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Can we talk about ORM Crisis?

A Basic Guide to the Methodology of Data Modeling for MongoDB

Django Bootstrap Base Template

DevOps: Any types of Cloud Service Should we know as DevOps

SellBay — Sell your vehicle here

First Real Life Web Automation Project

How Much Does It Cost To Hire A Developer For Your PHP Website

Collections of Knowledge

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Will

Will

More from Medium

Damn Vulnerable DeFi Challenge #4 Solution — Side entrance

A Compact Smart Contract Development Guide for Non-Experts

How to build an application in Node JS and deploy Smart Contracts in Solidity on EVM (Ethereum)…

Can’t code smart contracts? No problem.