Saltar al contenido principal

SDKs

Conflux has SDKs for mainstream programming languages, including JavaScript, Golang, Java and Python. This is just a short introduction to the SDKs, for detailed usage info, check their respective documentation.

Official SDKs

js-conflux-sdk

If you are familiar with JavaScript or Node.js, or if you want to build a web site to interact with your contract, js-conflux-sdk is right for you. It has a lot of useful features.

const { Conflux } = require("js-conflux-sdk");

async function main() {
let conflux = new Conflux({
url: "https://test.confluxrpc.com",
networkId: 1,
});

let balance = await conflux.cfx.getBalance(
"cfxtest:aakkfzezns4h8ymx1cgmcnd4x3aev6e2he38nnu8sv"
);
console.log("balance: ", balance);
}

main().catch(console.log);

go-conflux-sdk

Golang is a great language: fast, easy to use, and stable. In blockchain world a lot projects are developing with Go. If you want to develop a backend service which needs to communicate with Conflux network, go-conflux-sdk suits for you.

package main

import (
"fmt"

conflux "github.com/Conflux-Chain/go-conflux-sdk"
)

func main() {
client, err := conflux.NewClient("https://test.confluxrpc.com")
if err != nil {
fmt.Println("failed to create client:", err)
return
}
defer client.Close()

epoch, err := client.GetEpochNumber()
if err != nil {
fmt.Println("failed to get epoch number:", err)
return
}

fmt.Println("Current epoch number:", epoch)
}

java-conflux-sdk

Java is really a long live programming language. java-conflux-sdk can be used to talk to a Conflux node. It is evolved from the web3j library. Some of web3j's utility functions also work on the Conflux network.

package conflux.sdk.examples;
import java.math.BigInteger;
import conflux.web3j.Cfx;

public class App {
public static void main(String[] args) throws Exception {
int retry = 3;
int intervalMills = 1000; // interval(milliseconds) between retry
Cfx cfx = Cfx.create("https://test.confluxrpc.com", retry, intervalMills);
BigInteger epoch = cfx.getEpochNumber().sendAndGet();
System.out.println("Current epoch: " + epoch);
}
}

python-conflux-sdk

python-conflux-sdk (also known as conflux_web3) is the official Python SDK for Conflux Core Space. It is built upon web3.py v6, and most of its API is consistent with web3.py, offering convenience for developers who wish to migrate their Python code from Ethereum. Por ejemplo:

# modified from https://web3py.readthedocs.io/en/stable/middleware.html#signing
from conflux_web3 import Web3
w3 = Web3("https://test.confluxrpc.com")
from conflux_web3.middleware import construct_sign_and_send_raw_middleware
from cfx_account import Account
acct = Account.create('KEYSMASH FJAFJKLDSKF7JKFDJ 1530')
w3.middleware_onion.add(construct_sign_and_send_raw_middleware(acct))
w3.cfx.default_account = acct.address

transaction = {
'to': w3.address.zero_address(),
'value': 22,
}
w3.cfx.send_transaction(transaction)

Online runnable examples (courtesy of Binder) are provided in the SDK documentation, available in both English and Chinese.

Solidity SDKs

thirdweb Solidity SDK

This SDK provides the tools needed to build custom smart contracts efficiently by offering a set of prebuilt base contracts and a set of reusable components, or extensions, that can be integrated into your own smart contracts.

Conflux-contracts

This is a Solidity package including common useful contracts in Conflux DAPP developments. Which is kindly like OpenZeppelin. Currenlty most used is Conflux InternalContracts.

OpenZeppelin

This is the famous library for secure smart contract development. Build on a solid foundation of community-vetted code.

  • Implementations of standards like ERC20 and ERC721.
  • Flexible role-based permissioning scheme.
  • Reusable Solidity components to build custom contracts and complex decentralized systems.

Community developed SDKs

thirdweb SDK

The SDK covers all aspects of the web3 development stack, including connecting to user’s wallets, interacting with the blockchain and smart contracts, decentralized storage, authentication, and more; enabling you to build scalable and performant web3 applications on any EVM-compatible blockchain.

cpp-conflux-sdk

The Conflux C++ API allows any C++ client to interact with a local or remote Conflux node based on JSON-RPC 2.0 protocol. With Conflux C++ API, user can easily manage accounts, send transactions, deploy smart contracts and query blockchain information.

CPP-SDK

.NET SDK

Nconflux is the .Net integration library for Conflux, simplifying the access and smart contract interaction with Conflux nodes.

Nconflux is developed targeting netcore 3.1 and .net 5, hence it is compatible with all the operating systems (Windows, Linux, MacOS, Android and OSX) and has been tested on cloud, mobile, desktop, Xbox, hololens and windows IoT.

Swift SDK