Create a dApp Environment

Prerequisites

1. The Network for Running the Smart Contract

Deploying and using a smart contract consumes computing resources (memory, CPU and storage). Therefore, it is recommended that developers tune and test their smart contracts on their private networks and confirm that their contracts are ready before deploying them on the testnet or mainnet.

2. Wallet Client

Wallet-cli is the XDC Network command-line wallet. Developers can use wallet-cli to post and deploy contracts on the mainnet as well as execute other operations.

Smart Contract Development

We recommend Remix as the coding environment for compiling and testing during the early development stages. We present a simple example of a contract code of data access to illustrate the process of compiling, deploying, and debugging.

1. Initiate the Private Chain

Ensure that the private chain in the prerequisite has been successfully deployed. Check the log message “Produce block successfully” of persistent block generation appears.

2. Develop Smart Contracts

Write the code and use Remix to compile and debug. Ensure that the logic of the code is correct and the code is bug-free.

3. Compile in SimpleWebCompiler

The compiler of XDC is slightly different from that of Ethereum and is still integrating with Remix. Therefore, we provide a temporary way of acquiring ABI and ByteCode instead of acquiring them directly from Remix. Write the code in SimpleWebCompiler and click the Compile button to attain ABI and ByteCode.

4. Deploy Smart Contract via Wallet-cli

Download Wallet-Cli and compile on it.

NOTE: Developers can change the config.conf if they need to connect to a different node or interface.

Initiate Wallet-Cli

#Command to initiate the wallet-CLI

After initiation, input the command to the portal. Import the private key and inquire if the remaining balance is correct.

Contract Deployment

A message of “Deploy the contract successfully” will be displayed upon the success of contract deployment.

Call the Contracts to Store and Query the Data

If the called function is constant, wallet-cli will return the results directly.

Last updated