> 
 > 
How to use Infura Conflux API? | Tokenview
More

How to use Infura Conflux API? | Tokenview

It's cool to build your Dapp on Conflux, then how do you get it started? Tokenview launched Conflux Infura Services which make you develop Conflux Dapp very easily. First, you need to sign up for a Tokenview developer account; then, choose the interface you use, which currently supports the JSON-RPC interface.

The following will guide you on how to use these interfaces and how to develop your Conflux Dapp using Node.js.

1. JSON-RPC

2. Conflux truffle

JSON-RPC

You can communicate with Conflux node by calpng the JSON-RPC interface through HTTPS, which is a stateless call, and when your call ends, the connection closes.

Simulate JSON-RPC Request

You can use Postman to call JSON-RPC, together with your apikey and your Conflux node URL information. Now let's call the API「 cfx_getBlockByHash 」to get the information of a block hash. For example:

0x02f0f3ec83331b95d461b08f3e30bb3e4effe37917123f2cdd932a9c35fefd83

Enter the Confux node URL path in Postman:

https://developer.tokenview.com/mainnet/conflux?apikey={YOUR_APIKEY}

Select the POST method, 'Raw' in Body, 'JSON (apppcation/json)' format, and fill in your request parameters in JSON format.

How to use Infura Conflux API

Notes for each parameter:

    {
'jsonrpc':'2.0', // Version,
'method':'cfx_getBlockByHash', // API name
'params':['0x02f0f3ec83331b95d461b08f3e30bb3e4effe37917123f2cdd932a9c35fefd83',true], // Parameter
'id':1
}

Cpck 'Send' to send the request, and you will see the result returned from Tokenview Conflux Infura.

How to use Infura Conflux API

Send JSON-RPC requests using Node.js

Let's use Node.js to call the Conflux Infura node URL through the code. Let’s calpng the interface「 cfx_getBlockByHash 」 to get a block hash, same as above,

0x02f0f3ec83331b95d461b08f3e30bb3e4effe37917123f2cdd932a9c35fefd83

The steps are as follows:

1. Install npm.

2. create file app.js

Typing in these codes:

How to use Infura Conflux API

3. start a command window, and execute node app.js, you will get the following result:

How to use Infura Conflux API

Conflux Truffle

Let's use conflux truffle to initialize the connection to the Conflux node and implement a contract deployment.

Open the command window and execute the following command:

1. Execute npm install -g conflux-truffle to install conflux truffle;

2. After the installation is complete, execute cfxtruffle -v to check the success of the installation;

3. Install conflux portal to create a conflux wallet, charge a fee for filling 10 cfx, deployment contracts, and then get your private key;

4. Execute the command cfxtruffle init cfxfirstproject to create the cfxtruffle project;

5. Modify the configuration information of the truffle-config.js file to connect the Conflux node.

How to use Infura Conflux API

6. Execute cfxtruffle create contract Coin to create the contract;

7. Execute cfxtruffle create migration Coin to generate the deployment script;

8. Execute cfxtruffle compile to compile the contract;

9. Execute cfxtruffle deploy to deploy the contract.

Thus, you have completed the process of creating and deploying your smart contract using Tokenview Conflux Infura, isn't it cool?

Go to Tokenview API Service system (https://services.tokenview.com/product/infura) to get your own apikey and start to create your Conflux Dapp Now!

How to use Infura Conflux API