Skip to Content

@cfxdevkit/core


@cfxdevkit/core / CoreTestClient

Class: CoreTestClient

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

Core Space Test Client Implementation

Extends

Implements

Constructors

Constructor

new CoreTestClient(config): CoreTestClient

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

Parameters

config

TestConfig

Returns

CoreTestClient

Overrides

CoreClient.constructor

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

TestClient.address

Inherited from

CoreClient.address


chainId

readonly chainId: number

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

Implementation of

TestClient.chainId

Inherited from

CoreClient.chainId


chainType

readonly chainType: "core"

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

Implementation of

TestClient.chainType

Inherited from

CoreClient.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

TestClient.callContract

Inherited from

CoreClient.callContract


estimateGas()

estimateGas(tx): Promise<bigint>

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

Parameters

tx

BaseTransaction

Returns

Promise<bigint>

Implementation of

TestClient.estimateGas

Inherited from

CoreClient.estimateGas


formatAmount()

formatAmount(amount): string

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

Parameters

amount

bigint

Returns

string

Implementation of

TestClient.formatAmount

Inherited from

CoreClient.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

TestClient.getBalance

Inherited from

CoreClient.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

TestClient.getBalanceRaw

Inherited from

CoreClient.getBalanceRaw


getBlockNumber()

getBlockNumber(): Promise<bigint>

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

Returns

Promise<bigint>

Implementation of

TestClient.getBlockNumber

Inherited from

CoreClient.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

TestClient.getChainId

Inherited from

CoreClient.getChainId


getGasPrice()

getGasPrice(): Promise<bigint>

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

Returns

Promise<bigint>

Implementation of

TestClient.getGasPrice

Inherited from

CoreClient.getGasPrice


getInternalTestClient()

getInternalTestClient(): object

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

Returns

account

account: Account | undefined

The Account of the Client.

batch?

optional batch: object

Flags for batch settings.

batch.multicall?

optional multicall: boolean | { batchSize?: number; wait?: number; }

Toggle to enable eth_call multicall aggregation.

Type Declaration

boolean

{ batchSize?: number; wait?: number; }

cacheTime

cacheTime: number

Time (in ms) that cached data will remain in memory.

ccipRead?

optional ccipRead: false | { request?: (parameters) => Promise<`0x${string}`>; }

CCIP Read  configuration.

Type Declaration

false

{ request?: (parameters) => Promise<`0x${string}`>; }

chain

chain: Chain | undefined

Chain for the client.

clearTxpool()

clearTxpool: () => Promise<void>

Returns

Promise<void>

createLocalNodeAccount()

createLocalNodeAccount: (args) => Promise<`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}`>

Parameters
args

CreateLocalNodeAccountParameters

Returns

Promise<`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}`>

extend()

extend: <client>(fn) => Client<Transport, Chain | undefined, Account | undefined, TestRpcSchema, { [K in string | number | symbol]: client[K] } & TestActions>

Type Parameters
client

client extends object & ExactPartial<ExtendableProtectedActions<Transport, Chain | undefined, Account | undefined>>

Parameters
fn

(client) => client

Returns

Client<Transport, Chain | undefined, Account | undefined, TestRpcSchema, { [K in string | number | symbol]: client[K] } & TestActions>

generateEmptyLocalNodeBlocks()

generateEmptyLocalNodeBlocks: (args) => Promise<GenerateEmptyLocalNodeBlocksReturnType>

Parameters
args

GenerateEmptyLocalNodeBlocksParameters

Returns

Promise<GenerateEmptyLocalNodeBlocksReturnType>

generateLocalNodeBlock()

generateLocalNodeBlock: (args) => Promise<`0x${string}`>

Parameters
args

GenerateLocalNodeBlockParameters

Returns

Promise<`0x${string}`>

getCurrentSyncPhase()

getCurrentSyncPhase: () => Promise<PhaseNameType>

Returns

Promise<PhaseNameType>

getLocalNodeAddresses()

getLocalNodeAddresses: () => Promise<GetLocalNodeAddressesReturnType>

Returns

Promise<GetLocalNodeAddressesReturnType>

key

key: string

A key for the client.

lockLocalNodeAccount()

lockLocalNodeAccount: (args) => Promise<boolean>

Parameters
args

LockLocalNodeAccountParameters

Returns

Promise<boolean>

mine()

mine: (args) => Promise<void>

Parameters
args

MineParameters

Returns

Promise<void>

name

name: string

A name for the client.

pollingInterval

pollingInterval: number

Frequency (in ms) for polling enabled actions & events. Defaults to 4_000 milliseconds.

request

request: EIP1193RequestFn<TestRpcSchema>

Request function wrapped with friendly error handling

transport

transport: TransportConfig<string, EIP1193RequestFn> & Record<string, any>

The RPC transport

type

type: string

The type of client.

uid

uid: string

A unique ID for the client.

unlockLocalNodeAccount()

unlockLocalNodeAccount: (args) => Promise<boolean>

Parameters
args

UnlockLocalNodeAccountParameters

Returns

Promise<boolean>


getStorageAt()

getStorageAt(_address, _slot): Promise<string>

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

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}`

_slot

string

Returns

Promise<string>

Implementation of

TestClient.getStorageAt


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

TestClient.getTokenBalance

Inherited from

CoreClient.getTokenBalance


impersonateAccount()

impersonateAccount(_address): Promise<void>

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

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<void>

Implementation of

TestClient.impersonateAccount


increaseTime()

increaseTime(_seconds): Promise<void>

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

Parameters

_seconds

number

Returns

Promise<void>

Implementation of

TestClient.increaseTime


isValidAddress()

isValidAddress(address): boolean

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

Parameters

address

string

Returns

boolean

Implementation of

TestClient.isValidAddress

Inherited from

CoreClient.isValidAddress


mine()

mine(blocks?): Promise<void>

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

Parameters

blocks?

number = 1

Returns

Promise<void>

Implementation of

TestClient.mine


parseAmount()

parseAmount(amount): bigint

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

Parameters

amount

string

Returns

bigint

Implementation of

TestClient.parseAmount

Inherited from

CoreClient.parseAmount


sendTransaction()

sendTransaction(_tx): Promise<string>

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

Parameters

_tx

BaseTransaction

Returns

Promise<string>

Implementation of

TestClient.sendTransaction

Inherited from

CoreClient.sendTransaction


setBalance()

setBalance(_address, _balance): Promise<void>

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

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}`

_balance

bigint

Returns

Promise<void>

Implementation of

TestClient.setBalance


setNextBlockTimestamp()

setNextBlockTimestamp(_timestamp): Promise<void>

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

Parameters

_timestamp

number

Returns

Promise<void>

Implementation of

TestClient.setNextBlockTimestamp


setStorageAt()

setStorageAt(_address, _slot, _value): Promise<void>

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

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}`

_slot

string

_value

string

Returns

Promise<void>

Implementation of

TestClient.setStorageAt


stopImpersonatingAccount()

stopImpersonatingAccount(_address): Promise<void>

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

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<void>

Implementation of

TestClient.stopImpersonatingAccount


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

TestClient.waitForTransaction

Inherited from

CoreClient.waitForTransaction


watchBlocks()

watchBlocks(callback): UnwatchFunction

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

Parameters

callback

EventCallback<BlockEvent>

Returns

UnwatchFunction

Implementation of

TestClient.watchBlocks

Inherited from

CoreClient.watchBlocks


watchTransactions()

watchTransactions(callback): UnwatchFunction

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

Parameters

callback

EventCallback<TransactionEvent>

Returns

UnwatchFunction

Implementation of

TestClient.watchTransactions

Inherited from

CoreClient.watchTransactions