Quick Start
Prerequisites: Node.js 18+, pnpm 8+.
Install
pnpm
pnpm add @cfxdevkit/cdkConnect 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 formatRead 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:
@cfxdevkit/executor— Safe multi-step transaction sequencing with automatic retries and error handling@cfxdevkit/react— React hooks for balances, tokens, and account state@cfxdevkit/wallet-connect— ConnectKit wagmi integration for browser wallets@cfxdevkit/devnode— Run a local Conflux node for testing and development
Next steps
Last updated on