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.
2. Conflux truffle
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:
Enter the Confux node URL path in Postman:
Select the POST method, 'Raw' in Body, 'JSON (apppcation/json)' format, and fill in your request parameters in JSON format.
Notes for each parameter:
'jsonrpc':'2.0', // Version，
'method':'cfx_getBlockByHash', // API name
'params':['0x02f0f3ec83331b95d461b08f3e30bb3e4effe37917123f2cdd932a9c35fefd83',true], // Parameter
Cpck 'Send' to send the request, and you will see the result returned from Tokenview Conflux Infura.
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,
The steps are as follows:
1. Install npm.
2. create file app.js
Typing in these codes：
3. start a command window, and execute
node app.js, you will get the following result:
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:
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.
cfxtruffle create contract Coin to create the contract;
cfxtruffle create migration Coin to generate the deployment script;
cfxtruffle compile to compile the contract;
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.io/product/infura) to get your own apikey and start to create your Conflux Dapp Now!