Skip to Content

Quick Start

Prerequisites: Node.js 18+, pnpm 8+.

Install

pnpm add @cfxdevkit/cdk

Connect to Conflux eSpace

import { createClient, http } from '@cfxdevkit/cdk/client' import { espaceTestnet } from '@cfxdevkit/cdk/chains' const client = createClient({ chain: espaceTestnet, transport: http(), }) const block = await client.getBlockNumber() console.log('Block:', block)

Create a wallet

import { signerFromPrivateKey } from '@cfxdevkit/cdk/wallet' const signer = signerFromPrivateKey('0xYOUR_PRIVATE_KEY') console.log('eSpace address:', signer.address) console.log('Core address:', signer.coreAddress) // Base32 format

Read a contract

import { createClient, http } from '@cfxdevkit/cdk/client' import { espaceTestnet } from '@cfxdevkit/cdk/chains' const client = createClient({ chain: espaceTestnet, transport: http() }) const balance = await client.readContract({ address: '0xYOUR_CONTRACT', abi: [{ name: 'balanceOf', type: 'function', inputs: [{ type: 'address' }], outputs: [{ type: 'uint256' }] }], functionName: 'balanceOf', args: ['0xYOUR_WALLET'], })

Deploy a contract

import { createClient, http } from '@cfxdevkit/cdk/client' import { signerFromPrivateKey } from '@cfxdevkit/cdk/wallet' import { espaceTestnet } from '@cfxdevkit/cdk/chains' import { compileContract } from '@cfxdevkit/compiler' const client = createClient({ chain: espaceTestnet, transport: http() }) const signer = signerFromPrivateKey(process.env.PRIVATE_KEY!) // Compile your Solidity const { abi, bytecode } = await compileContract('MyToken.sol', source) // Deploy const hash = await client.deployContract({ abi, bytecode, account: signer, }) const receipt = await client.waitForTransactionReceipt({ hash }) console.log('Deployed at:', receipt.contractAddress)

Next packages to try

Once you’ve got the basics working, explore these packages:


Next steps

Last updated on