Skip to main content

How to Use Infura Conflux API?

tokenviewAbout 2 min

How to Use Infura Conflux API?

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 accountopen in new window; 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 Postmanopen in new window 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.io/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
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 
        }

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

How to use Infura Conflux API
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 npmopen in new window.

  2. create file app.js

Typing in these codes:

How to use Infura Conflux API
How to use Infura Conflux API
  1. start a command window, and execute node app.js, you will get the following result:

  2. How to use Infura Conflux API
    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 truffleopen in new window;

  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
How to use Infura Conflux API
  1. Execute cfxtruffle create contract Coin to create the contract;

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

  3. Execute cfxtruffle compile to compile the contract;

  4. 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 systemopen in new window to get your own apikey and start to create your Conflux Dapp Now!

How to use Infura Conflux API
How to use Infura Conflux API

About Tokenview Blockchain APIs & Data Service Platform:

Tokenview blockchain APIs & data service platform contained 120+ blockchains has powerful endpoints that simplify complex blockchain data into single API calls. Code for all supported blockchains using unified API calls. From here to easily get transaction, address, gas, contract, token, NFT, logs and any information from chain. And Yes you can also send tx to chain. One-click configuration with APIKey helps developers to Use, to Create, to Build.
Last update: