Javascript SDK
- CONST.js
- Conflux.js
- Conflux
- constructor
- provider
- wallet
- defaultGasPrice
- defaultGasRatio
- defaultStorageRatio
- Contract
- InternalContract
- close
- getSupplyInfo
- getStatus
- getGasPrice
- getInterestRate
- getAccumulateInterestRate
- getAccount
- getBalance
- getStakingBalance
- getNextNonce
- getAdmin
- getVoteList
- getDepositList
- getEpochNumber
- getBlockByEpochNumber
- getBlocksByEpochNumber
- getBestBlockHash
- getBlockByHash
- getConfirmationRiskByHash
- getTransactionByHash
- getTransactionReceipt
- sendRawTransaction
- sendTransaction
- getCode
- getStorageAt
- getStorageRoot
- getSponsorInfo
- getCollateralForStorage
- call
- estimateGasAndCollateral
- getLogs
- traceBlock
- subscribe
- subscribeEpochs
- subscribeNewHeads
- subscribeLogs
- unsubscribe
- Conflux
- Drip.js
- Message.js
- Transaction.js
- contract
- Contract.js
- Contract
- Contract.js
- provider
- BaseProvider.js
- BaseProvider
- HttpProvider.js
- WebSocketProvider.js
- WebSocketProvider
- index.js
- BaseProvider.js
- subscribe
- PendingTransaction.js
- Subscription.js
- util
- format.js
- format
- (static)any
- (static)uInt
- (static)bigInt
- (static)bigUInt
- (static)bigUIntHex
- (static)big
- (static)fixed64
- (static)epochNumber
- (static)hex
- (static)address
- (static)checksumAddress
- (static)blockHash
- (static)transactionHash
- (static)privateKey
- (static)publicKey
- (static)hexBuffer
- (static)bytes
- (static)boolean
- (static)keccak256
- format
- sign.js
- format.js
- wallet
- PrivateKeyAccount.js
- Wallet.js
EPOCH_NUMBER
epochNumber label
LATEST_MINED
'latest_mined': latest epoch.LATEST_STATE
'latest_state': latest state, about 5 epoch less thenLATEST_MINED
LATEST_CONFIRMED
'latest_confirmed': latest epoch which confirmation risk less 1e-8.LATEST_CHECKPOINT
'latest_checkpoint': latest check point epoch.EARLIEST
'earliest': earliest epoch number, same as 0.
MIN_GAS_PRICE
number
min gas price for transaction
- Examples
TRANSACTION_GAS
number
gas use for pure transfer transaction
- Examples
TRANSACTION_STORAGE_LIMIT
number
storage limit for pure transfer transaction
Conflux
A sdk of conflux.
Conflux.prototype.constructor
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
options | object | false | Conflux and Provider constructor options. | |
options.defaultGasPrice | string,number | false | The default gas price in drip to use for transactions. | |
options.defaultGasRatio | number | false | 1.1 | The ratio to multiply by gas. |
options.defaultStorageRatio | number | false | 1.1 | The ratio to multiply by storageLimit. |
options.url | string | false | Url of Conflux node to connect. | |
options.timeout | number | false | Request time out in ms | |
options.logger | Object | false | Logger object with 'info' and 'error' method. |
- Examples
Conflux.prototype.provider
WebsocketProvider,HttpProvider,BaseProvider
Provider for rpc call
Conflux.prototype.wallet
Wallet
Wallet for sendTransaction
to get Account
by from
field
Conflux.prototype.defaultGasPrice
number,string
Default gas price for following methods:
Conflux.sendTransaction
Conflux.prototype.defaultGasRatio
number
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
Conflux.prototype.defaultStorageRatio
number
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
Conflux.prototype.Contract
A shout cut for new Contract(options, conflux);
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
options | object | true | See Contract.constructor |
- Returns
Contract
- A Contract instance
Conflux.prototype.InternalContract
Create internal contract by default abi and address
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
name | "AdminControl","SponsorWhitelistControl","Staking" | true | Internal contract name |
- Returns
Contract
- Examples
Conflux.prototype.close
close connection.
- Examples
Conflux.prototype.getSupplyInfo
Get supply info
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
epochNumber | string,number | false | 'latest_state' | See format.epochNumber |
- Returns
Promise.<object>
Return supply info
- totalIssued
BigInt
: Total issued balance inDrip
- totalStaking
BigInt
: Total staking balance inDrip
- totalCollateral
BigInt
: Total collateral balance inDrip
- Examples
Conflux.prototype.getStatus
Get status
- Returns
Promise.<object>
Status information object
- 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
- Examples
Conflux.prototype.getGasPrice
Returns the current price per gas in Drip.
- Returns
Promise.<BigInt>
Gas price in drip.
- Examples
Conflux.prototype.getInterestRate
Returns the interest rate of given parameter.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
epochNumber | string,number | false | 'latest_state' | See format.epochNumber |
- Returns
Promise.<BigInt>
The interest rate of given parameter.
- Examples
Conflux.prototype.getAccumulateInterestRate
Returns the accumulate interest rate of given parameter.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
epochNumber | string,number | false | 'latest_state' | See format.epochNumber |
- Returns
Promise.<BigInt>
The accumulate interest rate of given parameter.
- Examples
Conflux.prototype.getAccount
Return account related states of the given account
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
address | string | true | address to get account. | |
epochNumber | string,number | false | 'latest_state' | See format.epochNumber |
- Returns
Promise.<object>
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.
- Examples
Conflux.prototype.getBalance
Returns the balance of the account of given address.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
address | string | true | The address to get the balance of. | |
epochNumber | string,number | false | 'latest_state' | See format.epochNumber |
- Returns
Promise.<BigInt>
The balance in Drip.
- Examples
Conflux.prototype.getStakingBalance
Returns the balance of the staking account of given address.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
address | string | true | Address to check for staking balance. | |
epochNumber | string,number | false | 'latest_state' | See format.epochNumber |
- Returns
Promise.<BigInt>
The staking balance in Drip.
- Examples
Conflux.prototype.getNextNonce
Returns the next nonce should be used by given address.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
address | string | true | The address to get the numbers of transactions from. | |
epochNumber | string,number | false | See format.epochNumber |
- Returns
Promise.<BigInt>
The next nonce should be used by given address.
- Examples
Conflux.prototype.getAdmin
Returns the admin of given contract.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
address | string | true | Address to contract. | |
epochNumber | string,number | false | 'latest_state' | See format.epochNumber |
- Returns
Promise.<string>
Address to admin, or null
if the contract does not exist.
- Examples
Conflux.prototype.getVoteList
Returns vote list of the given account.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
address | string | true | Address to contract. | |
epochNumber | string,number | false | 'latest_state' | See format.epochNumber |
- Returns
Promise.<Array.<object>>
Vote list
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.
- amount
Conflux.prototype.getDepositList
Returns deposit list of the given account.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
address | string | true | Address to contract. | |
epochNumber | string,number | false | 'latest_state' | See format.epochNumber |
- Returns
Promise.<Array.<object>>
Deposit list
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
- amount
Conflux.prototype.getEpochNumber
Returns the epoch number of given parameter.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
epochNumber | string,number | false | 'latest_state' | See format.epochNumber |
- Returns
Promise.<number>
integer of the current epoch number of given parameter.
- Examples
Conflux.prototype.getBlockByEpochNumber
Returns information about a block by epoch number.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
epochNumber | string,number | true | See format.epochNumber | |
detail | boolean | false | false | If true it returns the full transaction objects, if false only the hashes of the transactions. |
- Returns
Promise.<(object|null)>
See getBlockByHash
- Examples
Conflux.prototype.getBlocksByEpochNumber
Returns hashes of blocks located in some epoch.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
epochNumber | string,number | true | See format.epochNumber |
- Returns
Promise.<Array.<string>>
Array of block hashes, sorted by execution(topological) order.
- Examples
Conflux.prototype.getBestBlockHash
Returns the hash of best block.
- Returns
Promise.<string>
hash of the best block.
- Examples
Conflux.prototype.getBlockByHash
Returns information about a block by hash.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
blockHash | string | true | hash of a block. | |
detail | boolean | false | false | If true it returns the full transaction objects, if false only the hashes of the transactions. |
- Returns
Promise.<(object|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
: Hash of the generated proof-of-work.null
when its pending block. - parentHash
string
: Hash of the parent block. - powQuality
string
:Hash of the generated proof-of-work.null
when its pending block. - refereeHashes
string[]
: Array of referee hashes. - size
number
: Integer the size of this block in bytes. - timestamp
number
: The unix timestamp for when the block was collated. - transactions
string[]|object[]
: Array of transaction objects, or 32 Bytes transaction hashes depending on the last given parameter. - transactionsRoot
string
: The hash of the transactions of the block.
- Examples
Conflux.prototype.getConfirmationRiskByHash
Get the risk of the block could be reverted. All block in one same epoch returned same risk number
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
blockHash | string | true | Hash of a block |
- Returns
Promise.<(number|null)>
Number >0 and <1
- Examples
Conflux.prototype.getTransactionByHash
Returns the information about a transaction requested by transaction hash.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
transactionHash | string | true | hash of a transaction |
- Returns
Promise.<(object|null)>
transaction object, or null
when no transaction was found:
- blockHash
string
: hash of the block where this transaction was in and got executed.null
when its pending. - contractCreated
string|null
: address of created contract.null
when it's not a contract creating transaction - data
string
: the data send along with the transaction. - epochHeight
number
: epoch height - from
string
: address of the sender. - gas
BigInt
: gas provided by the sender. - gasPrice
number
: gas price provided by the sender in Drip. - hash
string
: hash of the transaction. - nonce
BigInt
: the number of transactions made by the sender prior to this one. - r
string
: ECDSA signature r - s
string
: ECDSA signature s - status
number
: 0 for success, 1 for error occured,null
when the transaction is skipped or not packed. - storageLimit
BigInt
: storage limit in bytes - chainId
number
: chain id - to
string
: address of the receiver. null when its a contract creation transaction. - transactionIndex
number
: integer of the transactions's index position in the block.null
when its pending. - v
string
: ECDSA recovery id - value
BigInt
: value transferred in Drip.
- Examples
Conflux.prototype.getTransactionReceipt
Returns the information about a transaction receipt requested by transaction hash.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
transactionHash | string | true | Hash of a transaction |
- Returns
Promise.<(object|null)>
A transaction receipt object, or null when no transaction was found or the transaction was not executed yet:
- transactionHash
string
: Hash of the given transaction. - index
number
: Transaction index within the block. - blockHash
string
: Hash of the block where this transaction was in and got executed. - epochNumber
number
: Epoch number of the block where this transaction was in and got executed. - from
string
: Address of the sender. - to
string
: Address of the receiver.null
when its a contract creation transaction. - gasUsed
number
: Gas used the transaction. - contractCreated
string|null
: Address of created contract.null
when it's not a contract creating transaction. - stateRoot
string
: Hash of the state root. - outcomeStatus
number
: the outcome status code, 0 was successful, 1 for an error occurred in the execution. - logsBloom
string
: Bloom filter for light clients to quickly retrieve related logs. - logs
object[]
: Array of log objects, which this transaction generated. - gasCoveredBySponsor
boolean
:true
if this transaction's gas fee was covered by the sponsor. - storageCoveredBySponsor
boolean
:true
if this transaction's storage collateral was covered by the sponsor. - storageCollateralized
BigInt
: the amount of storage collateral this transaction required. - storageReleased
array
: array of storage change objects, each specifying an address and the corresponding amount of storage collateral released- address
string
: address released - collaterals
BigInt
: corresponding amount of storage collateral released
- address
- Examples
Conflux.prototype.sendRawTransaction
Creates new message call transaction or a contract creation for signed transactions.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
hex | string,Buffer | true | The signed transaction data. |
- Returns
Promise.<PendingTransaction>
The transaction hash, or the zero hash if the transaction is not yet available.
- Examples
Conflux.prototype.sendTransaction
Sign and send transaction
if from
field in conflux.wallet
, sign by local account and send raw transaction,
else call cfx_sendTransaction
and sign by remote wallet
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
options | object | true | See Transaction | |
password | string | false | Password for remote node. |
- Returns
Promise.<PendingTransaction>
The PendingTransaction object.
- Examples
Conflux.prototype.getCode
Returns the code of given contract.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
address | string | true | Address to contract. | |
epochNumber | string,number | false | 'latest_state' | See format.epochNumber |
- Returns
Promise.<string>
Byte code of contract, or 0x if the contract does not exist.
- Examples
Conflux.prototype.getStorageAt
Returns storage entries from a given contract.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
address | string | true | Address to contract. | |
position | string | true | The given position. | |
epochNumber | string,number | false | 'latest_state' | See format.epochNumber |
- Returns
Promise.<(string|null)>
Storage entry of given query, or null if the it does not exist.
- Examples
Conflux.prototype.getStorageRoot
Returns the storage root of a given contract.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
address | string | true | Address to contract. | |
epochNumber | string,number | false | 'latest_state' | See format.epochNumber |
- Returns
Promise.<object>
A storage root object, or null
if the contract does not exist
- delta
string
: storage root in the delta trie. - intermediate
string
: storage root in the intermediate trie. - snapshot
string
: storage root in the snapshot.
- Examples
Conflux.prototype.getSponsorInfo
Returns the sponsor info of given contract.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
address | string | true | Address to contract. | |
epochNumber | string,number | false | 'latest_state' | See format.epochNumber |
- Returns
Promise.<object>
A sponsor info object, if the contract doesn't have a sponsor, then the all fields in returned object will be 0:
- sponsorBalanceForCollateral
BigInt
: the sponsored balance for storage. - sponsorBalanceForGas
BigInt
: the sponsored balance for gas. - sponsorGasBound
BigInt
: the max gas could be sponsored for one transaction. - sponsorForCollateral
string
: the address of the storage sponsor. - sponsorForGas
string
: the address of the gas sponsor.
- Examples
Conflux.prototype.getCollateralForStorage
Returns the size of the collateral storage of given address, in Byte.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
address | string | true | Address to check for collateral storage. | |
epochNumber | false | 'latest_state' | See format.epochNumber |
- Returns
Promise.<BigInt>
- The collateral storage in Byte.
- Examples
Conflux.prototype.call
Virtually call a contract, return the output data.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
options | object | true | See Transaction | |
epochNumber | string,number | false | 'latest_state' | See format.epochNumber |
- Returns
Promise.<string>
The output data.
Conflux.prototype.estimateGasAndCollateral
Virtually call a contract, return the estimate gas used and storage collateralized.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
options | object | true | See Transaction | |
epochNumber | string,number | false | 'latest_state' | See format.epochNumber |
- Returns
Promise.<object>
A estimate result object:
BigInt
gasUsed: The gas used.BigInt
gasLimit: The gas limit.BigInt
storageCollateralized: The storage collateralized in Byte.
Conflux.prototype.getLogs
Returns logs matching the filter provided.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
options | object | false | ||
options.fromEpoch | string,number | false | 'latest_checkpoint' | See format.epochNumber. Search will be applied from this epoch number. |
options.toEpoch | string,number | false | 'latest_state' | See format.epochNumber. Search will be applied up until (and including) this epoch number. |
options.blockHashes | Array.<string> | false | Array of up to 128 block hashes that the search will be applied to. This will override from/to epoch fields if it's not null | |
options.address | string,Array.<string> | false | Search contract addresses. If null, match all. If specified, log must be produced by one of these addresses. | |
options.topics | array | false | Search topics. Logs can have 4 topics: the function signature and up to 3 indexed event arguments. The elements of topics match the corresponding log topics. Example: ["0xA", null, ["0xB", "0xC"], null] matches logs with "0xA" as the 1st topic AND ("0xB" OR "0xC") as the 3rd topic. If null, match all. | |
options.limit | number | false | Return the last limit logs |
- Returns
Promise.<Array.<object>>
Array of log, that the logs matching the filter provided:
- address
string
: Address this event originated from. - topics
string[]
: Array of topics. - data
string
: The data containing non-indexed log parameter. - blockHash
string
: Hash of the block where the log in. - epochNumber
number
: Epoch number of the block where the log in. - transactionHash
string
: Hash of the transaction where the log in. - transactionIndex
string
: Transaction index in the block. - logIndex
number
: Log index in block. - transactionLogIndex
number
: Log index in transaction.
- Examples
Conflux.prototype.traceBlock
Return block's execution trace.
Note: need RPC server open trace_block method
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
blockHash | string | true | block hash |
- Returns
Promise.<Array.<object>>
Array of transaction traces.
- Examples
Conflux.prototype.subscribe
Subscribe event by name and got id, and provider will emit event by id
Note: suggest use
conflux.subscribeXXX
to subscribe
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
name | string | true | Subscription name | |
...args | array | true | Subscription arguments |
- Returns
Promise.<string>
Id of subscription
- Examples
Conflux.prototype.subscribeEpochs
The epochs topic streams consensus results: the total order of blocks, as expressed by a sequence of epochs. The returned series of epoch numbers is monotonically increasing with an increment of one. If you see the same epoch twice, this suggests a pivot chain reorg has happened (this might happen for recent epochs). For each epoch, the last hash in epochHashesOrdered is the hash of the pivot block.
- Returns
Promise.<Subscription>
EventEmitter instance with the follow events:
- 'data':
- epochNumber
number
: epoch number - epochHashesOrdered
array
: epoch block hash in orderstring
: block hash
- epochNumber
- Examples
Conflux.prototype.subscribeNewHeads
The newHeads topic streams all new block headers participating in the consensus.
- Returns
Promise.<Subscription>
EventEmitter instance with the follow events:
- 'data': see
getBlockByHash
- Examples
Conflux.prototype.subscribeLogs
The logs topic streams all logs matching a certain filter, in order. In case of a pivot chain reorg (which might affect recent logs), a special revert message is sent. All logs received previously that belong to epochs larger than the one in this message should be considered invalid.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
options | object | false | ||
options.address | string,Array.<string> | false | Search contract addresses. If null, match all. If specified, log must be produced by one of these addresses. | |
options.topics | array | false | Search topics. Logs can have 4 topics: the function signature and up to 3 indexed event arguments. The elements of topics match the corresponding log topics. Example: ["0xA", null, ["0xB", "0xC"], null] matches logs with "0xA" as the 1st topic AND ("0xB" OR "0xC") as the 3rd topic. If null, match all. |
- Returns
Promise.<Subscription>
EventEmitter instance with the follow events:
- 'data': see
getLogs
- 'revert':
- revertTo 'number': epoch number
- Examples
Conflux.prototype.unsubscribe
Unsubscribe subscription.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
id | string,Subscription | true | Subscription id |
- Returns
Promise.<boolean>
Is success
- Examples
Drip
Positive decimal integer string in Drip
Drip.fromCFX
Get Drip
string from CFX
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
value | string,number | true |
- Returns
Drip
- Examples
Drip.fromGDrip
Get Drip
string from GDrip
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
value | string,number | true |
- Returns
Drip
- Examples
Drip.prototype.constructor
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
value | number,string | true |
- Returns
Drip
- Examples
Drip.prototype.toCFX
Get CFX
number string
- Returns
string
- Examples
Drip.prototype.toGDrip
Get GDrip
number string
- Returns
string
- Examples
Message
Message.sign
Signs the hash with the privateKey.
TODO support CIP 23
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
privateKey | string,Buffer | true | ||
messageHash | string,Buffer | true |
- Returns
string
The signature as hex string.
- Examples
Message.recover
Recovers the signers publicKey from the signature.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
signature | string,Buffer | true | ||
messageHash | string,Buffer | true |
- Returns
string
The publicKey as hex string.
- Examples
Message.prototype.constructor
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
message | string | true |
- Returns
Message
- Examples
Message.prototype.hash
Getter of message hash include signature.
Note: calculate every time.
- Returns
string
Message.prototype.from
Getter of sender address.
Note: calculate every time.
- Returns
string,undefined
If ECDSA recover success return address, else return undefined.
Message.prototype.sign
Sign message and set 'r','s','v' and 'hash'.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
privateKey | string | true | Private key hex string. |
- Returns
Message
Transaction
Transaction.prototype.constructor
Create a transaction.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
options | object | true | ||
options.from | string | false | The sender address. | |
options.nonce | string,number | false | This allows to overwrite your own pending transactions that use the same nonce. | |
options.gasPrice | string,number | false | The price of gas for this transaction in drip. | |
options.gas | string,number | false | The amount of gas to use for the transaction (unused gas is refunded). | |
options.to | string | false | The destination address of the message, left undefined for a contract-creation transaction. | |
options.value | string,number | false | The value transferred for the transaction in drip, also the endowment if it’s a contract-creation transaction. | |
options.storageLimit | string,number | false | The storage limit specified by the sender. | |
options.epochHeight | string,number | false | The epoch proposed by the sender. Note that this is NOT the epoch of the block containing this transaction. | |
options.chainId | string,number | false | The chain ID specified by the sender. | |
options.data | string,Buffer | false | Either a ABI byte string containing the data of the function call on a contract, or in the case of a contract-creation transaction the initialisation code. | |
options.r | string,Buffer | false | ECDSA signature r | |
options.s | string,Buffer | false | ECDSA signature s | |
options.v | number | false | ECDSA recovery id |
- Returns
Transaction
Transaction.prototype.hash
Getter of transaction hash include signature.
Note: calculate every time.
- Returns
string,undefined
If transaction has r,s,v return hex string, else return undefined.
Transaction.prototype.sign
Sign transaction and set 'r','s','v'.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
privateKey | string | true | Private key hex string. |
- Returns
Transaction
Transaction.prototype.recover
Recover public key from signed Transaction.
- Returns
string
Transaction.prototype.encode
Encode rlp.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
includeSignature | boolean | false | false | Whether or not to include the signature. |
- Returns
Buffer
Transaction.prototype.serialize
Get the raw transaction hex string.
- Returns
string
Hex string
Contract
Contract with all its methods and events defined in its abi.
Contract.prototype.constructor
contract "code" definition:
6080................6080.................a264.........0033...............................| <- create contract transaction `data` -> || <- deploy code -> | <- runtime code -> | <- metadata -> | <- constructor arguments -> || <- contract `bytecode` -> || <- code as `getCode` -> |
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
options | object | true | ||
options.abi | array | true | The json interface for the contract to instantiate | |
options.address | string | false | The address of the smart contract to call, can be added later using contract.address = '0x1234...' | |
options.bytecode | string | false | The byte code of the contract, can be added later using contract.constructor.code = '0x1234...' | |
conflux | Conflux | true | Conflux instance. |
- Returns
object
- Examples
BaseProvider
BaseProvider.prototype.constructor
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
options | object | false | ||
options.url | string | true | Full json rpc http url | |
options.timeout | number | false | 60*1000 | Request time out in ms |
options.logger | object | false | Logger with info and error |
- Returns
BaseProvider
BaseProvider.prototype.requestId
Gen a random json rpc id.
It is used in call
method, overwrite it to gen your own id.
- Returns
string
BaseProvider.prototype.call
Call a json rpc method with params
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
method | string | true | Json rpc method name. | |
...params | array | false | Json rpc method params. |
- Returns
Promise.<*>
Json rpc method return value.
- Examples
BaseProvider.prototype.batch
Batch call json rpc methods with params
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
array | Array.<object> | true | Array of object with "method" and "params" |
- Returns
Promise.<Array>
- Examples
HttpProvider
Http protocol json rpc provider.
WebSocketProvider
Websocket protocol json rpc provider.
WebSocketProvider.prototype.constructor
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
options | object | false | See W3CWebSocket | |
options.url | string | true | Full json rpc http url | |
options.timeout | number | false | 60*1000 | Request time out in ms |
options.logger | object | false | Logger with info and error | |
options.protocols | Array.<string> | false | See w3 | |
options.origin | string | false | ||
options.headers | object | false | ||
options.requestOptions | object | false | ||
options.clientConfig | object | false | See websocket/lib/WebSocketClient | |
options.clientConfig.maxReceivedFrameSize | number | false | 0x100000 | 1MiB max frame size. |
options.clientConfig.maxReceivedMessageSize | number | false | 0x800000 | 8MiB max message size, only applicable if assembleFragments is true |
options.clientConfig.closeTimeout | number | false | 5000 | The number of milliseconds to wait after sending a close frame for an acknowledgement to come back before giving up and just closing the socket. |
- Returns
WebSocketProvider
providerFactory
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
options | object | true | ||
options.url | string | true |
- Returns
WebsocketProvider,HttpProvider,BaseProvider
- Examples
Subscription
Subscription event emitter
format.any
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
arg | any | true |
- Returns
any
arg
- Examples
format.uInt
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
arg | number,BigInt,string,boolean | true |
- Returns
Number
- Examples
format.bigInt
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
arg | number,string,BigInt | true |
- Returns
BigInt
- Examples
format.bigUInt
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
arg | number,string,BigInt | true |
- Returns
BigInt
- Examples
format.bigUIntHex
When encoding QUANTITIES (integers, numbers): encode as hex, prefix with "0x", the most compact representation (slight exception: zero should be represented as "0x0")
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
arg | number,string,BigInt | true |
- Returns
string
Hex string
- Examples
format.big
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
arg | number,string,BigInt | true |
- Returns
Big
Big instance
- Examples
format.fixed64
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
arg | string,number,BigInt,Big | true |
- Returns
Number
- Examples
format.epochNumber
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
arg | number,string | true | number or label, See EPOCH_NUMBER |
- Returns
string
- Examples
format.hex
When encoding UNFORMATTED DATA (byte arrays, account addresses, hashes, bytecode arrays): encode as hex, prefix with "0x", two hex digits per byte.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
arg | number,BigInt,string,Buffer,boolean,null | true |
- Returns
string
Hex string
- Examples
format.address
Checks if a given string is a valid address. It will also check the checksum, if the address has upper and lowercase letters.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
arg | string,Buffer | true |
- Returns
string
Hex string
- Examples
format.checksumAddress
Will convert an upper or lowercase address to a checksum address.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
arg | string,Buffer | true |
- Returns
string
Checksum address hex string
- Examples
format.blockHash
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
arg | string,Buffer | true |
- Returns
string
Hex string
- Examples
format.transactionHash
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
arg | string,Buffer | true |
- Returns
string
Hex string
- Examples
format.privateKey
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
arg | string,Buffer | true |
- Returns
string
Hex string
- Examples
format.publicKey
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
arg | string,Buffer | true |
- Returns
string
Hex string
- Examples
format.hexBuffer
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
arg | number,string,BigInt,Buffer,boolean,null | true |
- Returns
Buffer
- Examples
format.bytes
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
arg | string,Buffer,array | true |
- Returns
Buffer
- Examples
format.boolean
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
arg | boolean | true |
- Returns
boolean
- Examples
format.keccak256
Compute the keccak256 cryptographic hash of a value, returned as a hex string.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
arg | string,Buffer | true |
- Returns
string
- Examples
keccak256
keccak 256
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
buffer | Buffer | true |
- Returns
Buffer
- Examples
checksumAddress
Makes a checksum address
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
address | string | true | Hex string |
- Returns
string
- Examples
randomBuffer
gen a random buffer with size
bytes.
Note: call
crypto.randomBytes
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
size | number | true |
- Returns
Buffer
- Examples
randomPrivateKey
Gen a random PrivateKey buffer.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
entropy | Buffer | true |
- Returns
Buffer
- Examples
privateKeyToPublicKey
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
privateKey | Buffer | true |
- Returns
Buffer
publicKeyToAddress
Get account address by public key.
Account address hex starts with '0x1'
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
publicKey | Buffer | true |
- Returns
Buffer
- Examples
privateKeyToAddress
Get address by private key.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
privateKey | Buffer | true |
- Returns
Buffer
- Examples
ecdsaSign
Sign ecdsa
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
hash | Buffer | true | ||
privateKey | Buffer | true |
- Returns
object
ECDSA signature object.
- r {Buffer}
- s {Buffer}
- v {number}
- Examples
ecdsaRecover
Recover ecdsa
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
hash | Buffer | true | ||
options | object | true | ||
options.r | Buffer | true | ||
options.s | Buffer | true | ||
options.v | number | true |
- Returns
Buffer
publicKey
- Examples
encrypt
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
privateKey | Buffer | true | ||
password | string,Buffer | true |
- Returns
object
- keystoreV3 object
- Examples
decrypt
Decrypt account encrypt info.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
keystoreV3 | object | true | ||
password | string,Buffer | true |
- Returns
Buffer
Buffer of private key
- Examples
PrivateKeyAccount
PrivateKeyAccount.random
Create a new PrivateKeyAccount with random privateKey.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
entropy | string,Buffer | false | Entropy of random account |
- Returns
PrivateKeyAccount
- Examples
PrivateKeyAccount.decrypt
Decrypt account encrypt info.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
keystore | object | true | Keystore version 3 object. | |
password | string,Buffer | true | Password for keystore to decrypt with. |
- Returns
PrivateKeyAccount
- Examples
PrivateKeyAccount.prototype.constructor
Create a account by privateKey.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
privateKey | string,Buffer | true | Private key of account |
- Returns
PrivateKeyAccount
- Examples
PrivateKeyAccount.prototype.encrypt
Encrypt account privateKey to object.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
password | string | true |
- Returns
object
- keystoreV3 object
- Examples
PrivateKeyAccount.prototype.signTransaction
Sign a transaction.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
options | object | true | See Transaction |
- Returns
Promise.<Transaction>
- Examples
PrivateKeyAccount.prototype.signMessage
Sign a string.
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
options | string | true |
- Returns
Promise.<Message>
- Examples
Wallet
Wallet to manager accounts.
Wallet.prototype.has
Check if address exist
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
address | string | true |
- Returns
boolean
Wallet.prototype.delete
Drop one account by address
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
address | string | true |
- Returns
boolean
Wallet.prototype.clear
Drop all account in wallet
Wallet.prototype.set
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
address | string | true | Key of account, usually is address | |
account | Account | true | Account instance |
- Returns
Wallet
Wallet.prototype.get
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
address | string | true |
- Returns
Account
Wallet.prototype.addPrivateKey
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
privateKey | string,Buffer | true | Private key of account |
- Returns
PrivateKeyAccount
Wallet.prototype.addRandom
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
entropy | string,Buffer | false | Entropy of random account |
- Returns
PrivateKeyAccount
Wallet.prototype.addKeystore
- Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
keystore | object | true | Keystore version 3 object. | |
password | string,Buffer | true | Password for keystore to decrypt with. |
- Returns
PrivateKeyAccount