@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
Returns
CoreTestClient
Overrides
Properties
address
readonlyaddress:`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
Inherited from
chainId
readonlychainId:number
Defined in: packages/core/src/clients/core.ts:83
Implementation of
Inherited from
chainType
readonlychainType:"core"
Defined in: packages/core/src/clients/core.ts:82
Implementation of
Inherited from
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
Inherited from
estimateGas()
estimateGas(
tx):Promise<bigint>
Defined in: packages/core/src/clients/core.ts:170
Parameters
tx
Returns
Promise<bigint>
Implementation of
Inherited from
formatAmount()
formatAmount(
amount):string
Defined in: packages/core/src/clients/core.ts:484
Parameters
amount
bigint
Returns
string
Implementation of
Inherited from
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
Inherited from
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
Inherited from
getBlockNumber()
getBlockNumber():
Promise<bigint>
Defined in: packages/core/src/clients/core.ts:120
Returns
Promise<bigint>
Implementation of
Inherited from
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
Inherited from
getGasPrice()
getGasPrice():
Promise<bigint>
Defined in: packages/core/src/clients/core.ts:156
Returns
Promise<bigint>
Implementation of
Inherited from
getInternalTestClient()
getInternalTestClient():
object
Defined in: packages/core/src/clients/core.ts:979
Returns
account
account:
Account|undefined
The Account of the Client.
batch?
optionalbatch:object
Flags for batch settings.
batch.multicall?
optionalmulticall: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?
optionalccipRead: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
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
Inherited from
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
increaseTime()
increaseTime(
_seconds):Promise<void>
Defined in: packages/core/src/clients/core.ts:926
Parameters
_seconds
number
Returns
Promise<void>
Implementation of
isValidAddress()
isValidAddress(
address):boolean
Defined in: packages/core/src/clients/core.ts:480
Parameters
address
string
Returns
boolean
Implementation of
Inherited from
mine()
mine(
blocks?):Promise<void>
Defined in: packages/core/src/clients/core.ts:904
Parameters
blocks?
number = 1
Returns
Promise<void>
Implementation of
parseAmount()
parseAmount(
amount):bigint
Defined in: packages/core/src/clients/core.ts:488
Parameters
amount
string
Returns
bigint
Implementation of
Inherited from
sendTransaction()
sendTransaction(
_tx):Promise<string>
Defined in: packages/core/src/clients/core.ts:193
Parameters
_tx
Returns
Promise<string>
Implementation of
Inherited from
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
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
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
Inherited from
watchBlocks()
watchBlocks(
callback):UnwatchFunction
Defined in: packages/core/src/clients/core.ts:382
Parameters
callback
Returns
Implementation of
Inherited from
watchTransactions()
watchTransactions(
callback):UnwatchFunction
Defined in: packages/core/src/clients/core.ts:420
Parameters
callback
EventCallback<TransactionEvent>