Conflux
The Client class that provides an interface to the Conflux network.
The Client class that provides an interface to the Conflux network.
Kind: global class
- instance
- .getBlockByHashWithPivotAssumption(blockHash, pivotBlockHash, epochNumber) ⇒
Promise.<(Block|null)>
- static
Param | Type | Description |
---|---|---|
[options] | Conflux and Provider constructor options. |
Example
> const { Conflux } = require('js-conflux-sdk');
> const conflux = new Conflux({url:'https://test.confluxrpc.com', networkId: 1});
Example
> const conflux = new Conflux({
url: 'http://localhost:8000',
defaultGasPrice: 100,
logger: console,
});
Provider for rpc call
Wallet for
sendTransaction
to get Account
by from
fieldDeprecated
Default gas price for following methods:
Conflux.sendTransaction
If transaction.gas is undefined, gas will be set by estimate, cause gas used might be change during
estimateGasAndCollateral
and sendTransaction
, estimate value need to multiply by defaultGasRatio (>1.0) in case of gas not enough.transaction.gas = estimate.gasUsed * defaultGasRatio
Default gas price for following methods:
Conflux.sendTransaction
If transaction.storageLimit is undefined, storageLimit will be set by estimate, cause storage limit might be change during
estimateGasAndCollateral
and sendTransaction
, estimate value need to multiply by defaultStorageRatio (>1.0) in case of storageLimit not enough.transaction.storageLimit = estimate.storageCollateralized * defaultStorageRatio
Default gas price for following methods:
Conflux.sendTransaction
pos RPC methods
trace RPC methods
txpool RPC methods
cfx RPC methods
Advanced RPC compose methods
Different kind provider API wrapper
A shout cut for
new Contract(options, conflux);
Param | Type | Description |
---|---|---|
options | object |
Create internal contract by default abi and address
Param | Type | Description |
---|---|---|
name | "AdminControl" | "SponsorWhitelistControl" | "Staking" | "PoSRegister" | "CrossSpaceCall" | Internal contract name |
Example
> conflux.InternalContract('AdminControl')
{
constructor: [Function: bound call],
abi: ContractABI { * },
address: '0x0888000000000000000000000000000000000000',
destroy: [Function: bound call],
getAdmin: [Function: bound call],
setAdmin: [Function: bound call],
'destroy(address)': [Function: bound call],
'0x00f55d9d': [Function: bound call],
'getAdmin(address)': [Function: bound call],
'0x64efb22b': [Function: bound call],
'setAdmin(address,address)': [Function: bound call],
'0xc55b6bb7': [Function: bound call]
}
Create an token CRC20 contract with standard CRC20 abi
Param | Type |
---|---|
address | string |
Return a BatchRequester instance which can used to build batch request and decode response data
close connection.
> conflux.close();
Update conflux networkId from RPC
Get node client version
Get supply info
- totalIssued
BigInt
: Total issued balance inDrip
- totalStaking
BigInt
: Total staking balance inDrip
- totalCollateral
BigInt
: Total collateral balance inDrip
Param | Type | Default | Description |
---|---|---|---|
[epochNumber] | string | number | "'latest_state'" |
Example
> await conflux.getSupplyInfo()
{
totalCirculating: 28953062500000000000000n,
totalCollateral: 28953062500000000000000n,
totalIssued: 5033319899279074765657343554n,
totalStaking: 25026010834970490328077641n
}
Get status
- chainId
number
: Chain id - epochNumber
number
: Epoch number - blockNumber
number
: Block number - pendingTxNumber
number
: Pending transaction number - bestHash
string
: The block hash of best pivot block Example
> await conflux.getStatus()
{
chainId: 1029,
networkId: 1029,
epochNumber: 1117476,
blockNumber: 2230973,
pendingTxNumber: 4531,
bestHash: '0x8d581f13fa0548f2751450a7dabd871777875c9ccdf0d8bd629e07a7a5a7917a'
}
Returns the current price per gas in Drip.
> await conflux.getGasPrice();
1n
Returns the interest rate of given parameter.
Param | Type | Default | Description |
---|---|---|---|
[epochNumber] | string | number | "'latest_state'" |
Example
> await conflux.getInterestRate();
2522880000000n
Returns the accumulate interest rate of given parameter.
Kind: instance method of
Conflux
Returns: Promise.<BigInt>
- The accumulate interest rate of given parameter.Param | Type | Default | Description |
---|---|---|---|
[epochNumber] | string | number | "'latest_state'" |
Example
> await conflux.getAccumulateInterestRate()
76357297457647044505744908994993n
Return account related states of the given account
Kind: instance method of
Conflux
Returns: Promise.<Account>
- Return the states of the given account:- balance
BigInt
: the balance of the account. - nonce
BigInt
: the nonce of the account's next transaction. - codeHash
string
: the code hash of the account. - stakingBalance
BigInt
: the staking balance of the account. - collateralForStorage
BigInt
: the collateral storage of the account. - accumulatedInterestReturn
BigInt
: accumulated unterest return of the account. - admin
string
: admin of the account.
Param | Type | Default | Description |
---|---|---|---|
address | string | | address to get account. |
[epochNumber] | string | number | "'latest_state'" |
Example
> await conflux.getAccount('cfxtest:aasb661u2r60uzn5h0c4h63hj76wtgf552r9ghu7a4');
{
accumulatedInterestReturn: 0n,
balance: 824812401057514588670n,
collateralForStorage: 174187500000000000000n,
nonce: 1449n,
stakingBalance: 0n,
admin: 'CFXTEST:TYPE.NULL:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA6F0VRCSW',
codeHash: '0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470'
}
Returns the balance of the account of given address.
Param | Type | Default | Description |
---|---|---|---|
address | string | | The address to get the balance of. |
[epochNumber] | string | number | "'latest_state'" |
Example
> await conflux.getBalance("cfxtest:aasb661u2r60uzn5h0c4h63hj76wtgf552r9ghu7a4");
824812401057514588670n
Returns the balance of the staking account of given address.
Param | Type | Default | Description |
---|---|---|---|
address | string | | Address to check for staking balance. |
[epochNumber] | string | number | "'latest_state'" |
Example
> await conflux.getStakingBalance('cfxtest:aasb661u2r60uzn5h0c4h63hj76wtgf552r9ghu7a4', 'latest_state');
0n
Returns the next nonce should be used by given address.
Kind: instance method of
Conflux
Returns: Promise.<BigInt>
- The next nonce should be used by given address.Param | Type | Description |
---|---|---|
address | string | The address to get the numbers of transactions from. |
[epochNumber] | string | number |
Example
> await conflux.getNextNonce("cfxtest:aasb661u2r60uzn5h0c4h63hj76wtgf552r9ghu7a4");
1449n
Returns the admin of given contract.
Kind: instance method of
Conflux
Returns: Promise.<string>
- Address to admin, or null
if the contract does not exist.Param | Type | Default | Description |
---|---|---|---|
address | string | | Address to contract. |
[epochNumber] | string | number | "'latest_state'" |
Example
> conflux.getAdmin('cfxtest:achc8nxj7r451c223m18w2dwjnmhkd6rxa2gc31euw')
"CFXTEST:TYPE.USER:AASB661U2R60UZN5H0C4H63HJ76WTGF552R9GHU7A4"
Returns vote list of the given account.
array
:- amount
BigInt
: This is the number of tokens should be locked before - unlockBlockNumber
number
: This is the timestamp when the vote right will be invalid, measured in, the number of past blocks.
Param | Type | Default | Description |
---|---|---|---|
address | string | | Address to contract. |
[epochNumber] | string | number | "'latest_state'" |
Returns deposit list of the given account.
array
:- amount
BigInt
: the number of tokens deposited - accumulatedInterestRate:
BigInt
: the accumulated interest rate at the time of the deposit - depositTime
number
: the time of the deposit
Param | Type | Default | Description |
---|---|---|---|
address | string | | Address to contract. |
[epochNumber] | string | number | "'latest_state'" |
Returns the epoch number of given parameter.
Kind: instance method of
Conflux
Returns: Promise.<number>
- integer of the current epoch number of given parameter.Param | Type | Default | Description |
---|---|---|---|
[epochNumber] | string | number | "'latest_state'" |
Example
> await conflux.getEpochNumber();
443
Returns information about a block by epoch number.
Param | Type | Default | Description |
---|---|---|---|
epochNumber | string | number | | |
[detail] | boolean | false | If true it returns the full transaction objects, if false only the hashes of the transactions. |
Example
> await conflux.getBlockByEpochNumber('latest_mined', true);
{...}
Returns information about a block by block number.
Param | Type | Default | Description |
---|---|---|---|
blockNumber | string | number | | |
[detail] | boolean | false | If true it returns the full transaction objects, if false only the hashes of the transactions. |
Example
> await conflux.getBlockByBlockNumber('0x123', true);
{...}
Returns hashes of blocks located in some epoch.
Kind: instance method of
Conflux
Returns: Promise.<Array.<string>>
- Array of block hashes, sorted by execution(topological) order.Param | Type | Description |
---|---|---|
epochNumber | string | number |
Example
> await conflux.getBlocksByEpochNumber(0);
['0xe677ae5206a5d67d9efa183d867b4b986ed82a3e62174a1488cf8364d58534ec']
Get epoch blocks reward info
- blockHash
string
: Hash of the block. - author
string
: The address of the beneficiary to whom the mining rewards were given. - baseReward
BigInt
: Block base reward inDrip
- totalReward
BigInt
: Block total reward inDrip
- txFee
BigInt
: Total gas fee of block transaction
Param | Type | Description |
---|---|---|
epochNumber | string | number |
Example
> await conflux.getBlockRewardInfo(6);
[
{
baseReward: 6993700000000000000n,
totalReward: 6993700031741486703n,
txFee: 0n,
author: 'CFXTEST:TYPE.USER:AATXETSP0KDARPDB5STDYEX11DR3X6SB0J2XZETSG6',
blockHash: '0x73cd891aea310e2c0b8644de91746c7353cebfffb780126bc06101b20689c893'
},
{
baseReward: 6997200000000000000n,
totalReward: 6997200031760371742n,
txFee: 3000000n,
author: 'CFXTEST:TYPE.USER:AATXETSP0KDARPDB5STDYEX11DR3X6SB0J2XZETSG6',
blockHash: '0xaf4136d04e9e2cc470703251ec46f5913ab7955d526feed43771705e89c77390'
}
]
Returns the hash of best block.
> await conflux.getBestBlockHash();
"0xb8bb355bfeaf055a032d5b7df719917c090ee4fb6fee42383004dfe8911d7daf"
Returns information about a block by hash.
Kind: instance method of
Conflux
Returns: Promise.<(Block|null)>
- A block object, or null when no block was found:- adaptive
boolean
: Iftrue
the weight of the block is adaptive under GHAST rule, iffalse
otherwise. - blame
number
: If 0, then no blocks are blamed on its parent path, If greater than 0, then the nearest blamed block on the parent path is blame steps away. - deferredLogsBloomHash
string
: The bloom hash of deferred logs. - deferredReceiptsRoot
string
: The hash of the receipts of the block after deferred execution. - deferredStateRoot
string
: The root of the final state trie of the block after deferred execution. - difficulty
string
: Integer string of the difficulty for this block. - epochNumber
number|null
: The current block epoch number in the client's view. null when it's not in best block's past set and the epoch number is not determined. - gasLimit
BigInt
: The maximum gas allowed in this block. - hash
string|null
: Hash of the block.null
when its pending block. - height
number
: The block heights.null
when its pending block. - miner
string
: The address of the beneficiary to whom the mining rewards were given. - nonce
string