Skip to Content

@cfxdevkit/core


@cfxdevkit/core / CoreClient

Class: CoreClient

Defined in: packages/core/src/clients/core.ts:81

Core Space Client Implementation Wraps cive client with unified interface

Extended by

Implements

Constructors

Constructor

new CoreClient(config): CoreClient

Defined in: packages/core/src/clients/core.ts:89

Parameters

config

ClientConfig

Returns

CoreClient

Properties

address

readonly address: `CFX:TYPE.USER:${string}` | `CFX:TYPE.CONTRACT:${string}` | `CFX:TYPE.BUILTIN:${string}` | `CFX:TYPE.NULL:${string}` | `CFXTEST:TYPE.USER:${string}` | `CFXTEST:TYPE.CONTRACT:${string}` | `CFXTEST:TYPE.BUILTIN:${string}` | `CFXTEST:TYPE.NULL:${string}` | `NET${string}:TYPE.USER:${string}` | `NET${string}:TYPE.CONTRACT:${string}` | `NET${string}:TYPE.BUILTIN:${string}` | `NET${string}:TYPE.NULL:${string}` | `cfx:${string}` | `cfxtest:${string}` | `net${string}:${string}`

Defined in: packages/core/src/clients/core.ts:84

Implementation of

ChainClient.address


chainId

readonly chainId: number

Defined in: packages/core/src/clients/core.ts:83

Implementation of

ChainClient.chainId


chainType

readonly chainType: "core"

Defined in: packages/core/src/clients/core.ts:82

Implementation of

ChainClient.chainType

Methods

callContract()

callContract<T>(address, abi, functionName, args?): Promise<T>

Defined in: packages/core/src/clients/core.ts:293

Read a contract function (view/pure). Available on the public client — no wallet / private key required.

Type Parameters

T

T = unknown

Parameters

address

string

abi

unknown[]

functionName

string

args?

unknown[] = []

Returns

Promise<T>

Implementation of

ChainClient.callContract


estimateGas()

estimateGas(tx): Promise<bigint>

Defined in: packages/core/src/clients/core.ts:170

Parameters

tx

BaseTransaction

Returns

Promise<bigint>

Implementation of

ChainClient.estimateGas


formatAmount()

formatAmount(amount): string

Defined in: packages/core/src/clients/core.ts:484

Parameters

amount

bigint

Returns

string

Implementation of

ChainClient.formatAmount


getBalance()

getBalance(address): Promise<string>

Defined in: packages/core/src/clients/core.ts:134

Parameters

address

`CFX:TYPE.USER:${string}` | `CFX:TYPE.CONTRACT:${string}` | `CFX:TYPE.BUILTIN:${string}` | `CFX:TYPE.NULL:${string}` | `CFXTEST:TYPE.USER:${string}` | `CFXTEST:TYPE.CONTRACT:${string}` | `CFXTEST:TYPE.BUILTIN:${string}` | `CFXTEST:TYPE.NULL:${string}` | `NET${string}:TYPE.USER:${string}` | `NET${string}:TYPE.CONTRACT:${string}` | `NET${string}:TYPE.BUILTIN:${string}` | `NET${string}:TYPE.NULL:${string}` | `cfx:${string}` | `cfxtest:${string}` | `net${string}:${string}`

Returns

Promise<string>

Implementation of

ChainClient.getBalance


getBalanceRaw()

getBalanceRaw(address): Promise<bigint>

Defined in: packages/core/src/clients/core.ts:252

Get the raw balance as a bigint (in Drip, 1 CFX = 10^18 Drip). Use this when you need the exact value for arithmetic.

Parameters

address

`CFX:TYPE.USER:${string}` | `CFX:TYPE.CONTRACT:${string}` | `CFX:TYPE.BUILTIN:${string}` | `CFX:TYPE.NULL:${string}` | `CFXTEST:TYPE.USER:${string}` | `CFXTEST:TYPE.CONTRACT:${string}` | `CFXTEST:TYPE.BUILTIN:${string}` | `CFXTEST:TYPE.NULL:${string}` | `NET${string}:TYPE.USER:${string}` | `NET${string}:TYPE.CONTRACT:${string}` | `NET${string}:TYPE.BUILTIN:${string}` | `NET${string}:TYPE.NULL:${string}` | `cfx:${string}` | `cfxtest:${string}` | `net${string}:${string}`

Returns

Promise<bigint>

Implementation of

ChainClient.getBalanceRaw


getBlockNumber()

getBlockNumber(): Promise<bigint>

Defined in: packages/core/src/clients/core.ts:120

Returns

Promise<bigint>

Implementation of

ChainClient.getBlockNumber


getChainId()

getChainId(): Promise<number>

Defined in: packages/core/src/clients/core.ts:275

Get the chain ID from the connected node.

Returns

Promise<number>

Implementation of

ChainClient.getChainId


getGasPrice()

getGasPrice(): Promise<bigint>

Defined in: packages/core/src/clients/core.ts:156

Returns

Promise<bigint>

Implementation of

ChainClient.getGasPrice


getTokenBalance()

getTokenBalance(tokenAddress, holderAddress?): Promise<string>

Defined in: packages/core/src/clients/core.ts:317

Parameters

tokenAddress

`CFX:TYPE.USER:${string}` | `CFX:TYPE.CONTRACT:${string}` | `CFX:TYPE.BUILTIN:${string}` | `CFX:TYPE.NULL:${string}` | `CFXTEST:TYPE.USER:${string}` | `CFXTEST:TYPE.CONTRACT:${string}` | `CFXTEST:TYPE.BUILTIN:${string}` | `CFXTEST:TYPE.NULL:${string}` | `NET${string}:TYPE.USER:${string}` | `NET${string}:TYPE.CONTRACT:${string}` | `NET${string}:TYPE.BUILTIN:${string}` | `NET${string}:TYPE.NULL:${string}` | `cfx:${string}` | `cfxtest:${string}` | `net${string}:${string}`

holderAddress?

`CFX:TYPE.USER:${string}` | `CFX:TYPE.CONTRACT:${string}` | `CFX:TYPE.BUILTIN:${string}` | `CFX:TYPE.NULL:${string}` | `CFXTEST:TYPE.USER:${string}` | `CFXTEST:TYPE.CONTRACT:${string}` | `CFXTEST:TYPE.BUILTIN:${string}` | `CFXTEST:TYPE.NULL:${string}` | `NET${string}:TYPE.USER:${string}` | `NET${string}:TYPE.CONTRACT:${string}` | `NET${string}:TYPE.BUILTIN:${string}` | `NET${string}:TYPE.NULL:${string}` | `cfx:${string}` | `cfxtest:${string}` | `net${string}:${string}`

Returns

Promise<string>

Implementation of

ChainClient.getTokenBalance


isValidAddress()

isValidAddress(address): boolean

Defined in: packages/core/src/clients/core.ts:480

Parameters

address

string

Returns

boolean

Implementation of

ChainClient.isValidAddress


parseAmount()

parseAmount(amount): bigint

Defined in: packages/core/src/clients/core.ts:488

Parameters

amount

string

Returns

bigint

Implementation of

ChainClient.parseAmount


sendTransaction()

sendTransaction(_tx): Promise<string>

Defined in: packages/core/src/clients/core.ts:193

Parameters

_tx

BaseTransaction

Returns

Promise<string>

Implementation of

ChainClient.sendTransaction


waitForTransaction()

waitForTransaction(hash, timeout?): Promise<TransactionReceipt>

Defined in: packages/core/src/clients/core.ts:206

Wait for a transaction to be confirmed.

Parameters

hash

string

Transaction hash.

timeout?

number

Timeout in milliseconds (default: 30 000). Pass 0 for no timeout.

Returns

Promise<TransactionReceipt>

Implementation of

ChainClient.waitForTransaction


watchBlocks()

watchBlocks(callback): UnwatchFunction

Defined in: packages/core/src/clients/core.ts:382

Parameters

callback

EventCallback<BlockEvent>

Returns

UnwatchFunction

Implementation of

ChainClient.watchBlocks


watchTransactions()

watchTransactions(callback): UnwatchFunction

Defined in: packages/core/src/clients/core.ts:420

Parameters

callback

EventCallback<TransactionEvent>

Returns

UnwatchFunction

Implementation of

ChainClient.watchTransactions